Add nicer build script
This commit is contained in:
parent
3984bfb5db
commit
73fb8aa3dd
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,3 @@
|
||||||
node_modules
|
node_modules
|
||||||
build
|
dist
|
||||||
secrets.*.js
|
secrets.*.js
|
||||||
|
|
17
README.md
17
README.md
|
@ -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.
|
You're gonna need `npm` for building extension.
|
||||||
|
|
||||||
npm install
|
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
|
## 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
|
## Development
|
||||||
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
|
|
||||||
Check [CI config](./.circleci/config.yml) to figure out all the checks I'm doing.
|
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.
|
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
|
# 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>
|
* 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
58
build
Executable 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()
|
|
@ -14,6 +14,7 @@ const baseManifest = require('./src/manifest.json');
|
||||||
const target = env.TARGET;
|
const target = env.TARGET;
|
||||||
const pkg_name = env.ANY_HOST ? "grasp (any host)" : "grasp";
|
const pkg_name = env.ANY_HOST ? "grasp (any host)" : "grasp";
|
||||||
|
|
||||||
|
// TODO make permissions literate
|
||||||
const permissions = [
|
const permissions = [
|
||||||
"storage",
|
"storage",
|
||||||
"notifications",
|
"notifications",
|
||||||
|
@ -74,16 +75,19 @@ if (fileSystem.existsSync(secretsPath)) {
|
||||||
alias["secrets"] = secretsPath;
|
alias["secrets"] = secretsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const build_path = path.join(__dirname, "dist"); // TODO target??
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
mode: 'development',
|
mode: 'production',
|
||||||
entry: {
|
entry: {
|
||||||
popup: path.join(__dirname, "src", "js", "popup.js"),
|
popup : path.join(__dirname, "src", "js", "popup.js"),
|
||||||
options: path.join(__dirname, "src", "js", "options_page.js"),
|
options : path.join(__dirname, "src", "js", "options_page.js"),
|
||||||
background: path.join(__dirname, "src", "js", "background.js")
|
background: path.join(__dirname, "src", "js", "background.js")
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, "build"),
|
path: build_path,
|
||||||
filename: "[name].bundle.js"
|
// TODO why bundle???
|
||||||
|
filename: "[name].bundle.js",
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
|
@ -116,7 +120,7 @@ var options = {
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// clean the build folder
|
// clean the build folder
|
||||||
new CleanWebpackPlugin(["build/*"]),
|
new CleanWebpackPlugin([build_path + "/*"]),
|
||||||
new CopyWebpackPlugin([
|
new CopyWebpackPlugin([
|
||||||
{ from: 'src/img/*.png', flatten: true },
|
{ from: 'src/img/*.png', flatten: true },
|
||||||
]),
|
]),
|
||||||
|
@ -149,6 +153,7 @@ var options = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO https://webpack.js.org/configuration/devtool
|
||||||
if (env.NODE_ENV === "development") {
|
if (env.NODE_ENV === "development") {
|
||||||
options.devtool = "cheap-module-eval-source-map";
|
options.devtool = "cheap-module-eval-source-map";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue