Add nicer build script

This commit is contained in:
Dima Gerasimov 2019-12-09 20:43:38 +00:00 committed by Dmitrii Gerasimov
parent 3984bfb5db
commit 73fb8aa3dd
4 changed files with 79 additions and 15 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
node_modules
build
dist
secrets.*.js

View file

@ -65,22 +65,23 @@ The most up-to-date instructions should be in [CI config](./.circleci/config.yml
You're gonna need `npm` for building extension.
npm install
npm run build
./build --target <browser> # e.g. ./build --target chrome or ./build --target firefox
After that you can find the extension in `build` directory and 'Load unpacked** if necessary. There is also Flow and Eslint set up.
After that you can find the extension in `dist` directory and 'Load unpacked** if necessary. There is also Flow and Eslint set up.
## building any host version
If you do need unresticted url permissions, build the extensions like that: `ANY_HOST=yes npm run build`.
If you do need unresticted url permissions, build the extensions like that: `ANY_HOST=yes ./build`.
## building for Firefox
Default target is Chrome. use `TARGET=firefox npm run build` to build for firefox. The code is actually same, the only differences are minor appearance adjustments in manifest.
# Development
## Development
Check [CI config](./.circleci/config.yml) to figure out all the checks I'm doing.
The only test(s) that don't run on CI at the moment (e.g. due to lack of X server) are marked with `@skip_if_ci`. You can run them manually though.
Extra tests (not integrated in CI yet):
- `(cd dist && web-ext lint)`
- `scripts/test_with_browser.py`
# Credits
* Icon made by <a href="https://www.freepik.com/" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>, licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>

58
build Executable file
View file

@ -0,0 +1,58 @@
#!/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')
# TODO --lint?
tg = p.add_mutually_exclusive_group()
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
assert target is not None
maybe_release = {'NODE_ENV': 'production'} if args.release else {}
env = {
'TARGET': target,
**maybe_release,
**os.environ,
}
check_call([
'npm', 'run', 'build',
], env=env, cwd=str(Path(__file__).absolute().parent))
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))
dist_dir = Path(__file__).absolute().parent / 'dist'
src_dir = dist_dir / target
from firefox_dev_secrets import API_KEY, API_SECRET
check_call([
'web-ext',
'--source-dir' , str(src_dir),
'--artifacts-dir', str(dist_dir),
'--api-key' , API_KEY,
'--api-secret' , API_SECRET,
'sign',
])
if __name__ == '__main__':
main()

View file

@ -14,6 +14,7 @@ const baseManifest = require('./src/manifest.json');
const target = env.TARGET;
const pkg_name = env.ANY_HOST ? "grasp (any host)" : "grasp";
// TODO make permissions literate
const permissions = [
"storage",
"notifications",
@ -74,16 +75,19 @@ if (fileSystem.existsSync(secretsPath)) {
alias["secrets"] = secretsPath;
}
const build_path = path.join(__dirname, "dist"); // TODO target??
var options = {
mode: 'development',
mode: 'production',
entry: {
popup: path.join(__dirname, "src", "js", "popup.js"),
options: path.join(__dirname, "src", "js", "options_page.js"),
popup : path.join(__dirname, "src", "js", "popup.js"),
options : path.join(__dirname, "src", "js", "options_page.js"),
background: path.join(__dirname, "src", "js", "background.js")
},
output: {
path: path.join(__dirname, "build"),
filename: "[name].bundle.js"
path: build_path,
// TODO why bundle???
filename: "[name].bundle.js",
},
module: {
rules: [
@ -116,7 +120,7 @@ var options = {
},
plugins: [
// clean the build folder
new CleanWebpackPlugin(["build/*"]),
new CleanWebpackPlugin([build_path + "/*"]),
new CopyWebpackPlugin([
{ from: 'src/img/*.png', flatten: true },
]),
@ -149,6 +153,7 @@ var options = {
]
};
// TODO https://webpack.js.org/configuration/devtool
if (env.NODE_ENV === "development") {
options.devtool = "cheap-module-eval-source-map";
}