-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
dev
executable file
·57 lines (46 loc) · 1.67 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
#!/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', '--init', '-it', '--rm', '-v',
os.getcwd() + ':/src:cached', '-w=/src', 'node:12.10.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('Generate a zip file for releasing')
def release(args, remaining):
rc = run(DOCKER_RUN + ['yarn', 'run', 'release']).returncode
if not rc:
rc = run(['git', 'archive', '-o' 'web-ext-artifacts/source-code.zip',
'HEAD']).returncode
if not rc:
print('Updated the source code ZIP file')
return rc
@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 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()