2019-12-09 12:43:38 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
from subprocess import check_call
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
TARGETS = ['chrome', 'firefox']
|
|
|
|
# TODO FIXME copypaste from promnesia
|
|
|
|
# TODO FIXME use it in ci script
|
|
|
|
def main():
|
|
|
|
p = argparse.ArgumentParser()
|
|
|
|
# TODO rename to --production??
|
|
|
|
p.add_argument('--release', action='store_true')
|
|
|
|
p.add_argument('--sign', action='store_true')
|
2019-12-09 12:53:08 -08:00
|
|
|
p.add_argument('--lint', action='store_true')
|
2019-12-09 12:43:38 -08:00
|
|
|
|
2019-12-09 12:53:08 -08:00
|
|
|
tg = p.add_mutually_exclusive_group(required=True)
|
2019-12-09 12:43:38 -08:00
|
|
|
tg.add_argument('--target', type=str, choices=TARGETS)
|
|
|
|
for b in TARGETS:
|
|
|
|
tg.add_argument('--' + b, action='store_const', const=b, dest='target')
|
|
|
|
args = p.parse_args()
|
|
|
|
target = args.target
|
|
|
|
|
|
|
|
|
2019-12-09 12:53:08 -08:00
|
|
|
dist_dir = Path(__file__).absolute().parent / 'dist'
|
|
|
|
def webext(*args, **kwargs):
|
|
|
|
src_dir = dist_dir # / target
|
|
|
|
src_dir = src_dir.resolve() # TODO ugh. webext can't into symlinks???
|
|
|
|
check_call([
|
|
|
|
'web-ext',
|
|
|
|
'--source-dir', str(src_dir),
|
|
|
|
*args,
|
|
|
|
], **kwargs)
|
2019-12-09 12:43:38 -08:00
|
|
|
|
2019-12-09 12:53:08 -08:00
|
|
|
maybe_release = {'NODE_ENV': 'production'} if args.release else {}
|
2019-12-09 12:43:38 -08:00
|
|
|
env = {
|
|
|
|
'TARGET': target,
|
|
|
|
**maybe_release,
|
|
|
|
**os.environ,
|
|
|
|
}
|
|
|
|
check_call([
|
|
|
|
'npm', 'run', 'build',
|
|
|
|
], env=env, cwd=str(Path(__file__).absolute().parent))
|
|
|
|
|
2019-12-09 12:53:08 -08:00
|
|
|
if args.lint:
|
|
|
|
# TODO --self-hosted
|
|
|
|
# TODO warnings as errors??
|
|
|
|
webext('lint')
|
|
|
|
|
|
|
|
if args.release:
|
|
|
|
assert args.lint # TODO not sure..
|
|
|
|
|
2019-12-09 12:43:38 -08:00
|
|
|
if args.sign:
|
|
|
|
assert args.release
|
|
|
|
if target not in ['firefox', 'firefox-mobile']:
|
|
|
|
raise RuntimeError("{target} is not supported for signing yet".format(target=target))
|
|
|
|
|
|
|
|
|
|
|
|
from firefox_dev_secrets import API_KEY, API_SECRET
|
2019-12-09 12:53:08 -08:00
|
|
|
webext(
|
2019-12-09 12:43:38 -08:00
|
|
|
'--artifacts-dir', str(dist_dir),
|
2019-12-09 12:53:08 -08:00
|
|
|
'--api-key' , API_KEY,
|
|
|
|
'--api-secret', API_SECRET,
|
2019-12-09 12:43:38 -08:00
|
|
|
'sign',
|
2019-12-09 12:53:08 -08:00
|
|
|
)
|
2019-12-09 12:43:38 -08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|