-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev
executable file
·59 lines (46 loc) · 1.68 KB
/
dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import argparse
import os
from subprocess import run
import sys
parser = argparse.ArgumentParser(prog='./dev')
subparsers = parser.add_subparsers(metavar='<command>', title='commands')
DOCKER_RUN = ['docker', 'run', '-it', '--rm', '-v',
os.getcwd() + ':/src', '-w=/src', 'node:16.0.0-alpine']
def command(help):
def decorator(func):
parser = subparsers.add_parser(func.__name__, help=help)
parser.set_defaults(func=func)
return func
return decorator
@command('Format the code')
def format(args, remaining):
return run(DOCKER_RUN + ['yarn', 'run', 'format']).returncode
@command('Lint the code')
def lint(args, remaining):
return run(DOCKER_RUN + ['yarn', 'run', 'lint']).returncode
@command('Run before committing')
def precommit(args, remaining):
return run(DOCKER_RUN + ['yarn', 'run', 'prepublishOnly']).returncode
@command('Publish to the npm registry')
def publish(args, remaining):
return run(DOCKER_RUN + ['yarn', 'publish']).returncode
@command('Bring up a shell')
def sh(args, remaining):
return run(DOCKER_RUN + ['sh']).returncode
@command('Start development')
def start(args, remaining):
return run(DOCKER_RUN + ['yarn', 'start']).returncode
@command('Run the test suite')
def test(args, remaining):
return run(DOCKER_RUN + ['yarn', 'test']).returncode
@command('Run a Yarn command')
def yarn(args, remaining):
return run(DOCKER_RUN + ['yarn'] + remaining or []).returncode
if __name__ == '__main__':
if len(sys.argv) > 1:
args, remaining = parser.parse_known_args()
returncode = args.func(args, remaining)
sys.exit(returncode)
else:
parser.print_help()