Skip to content

Commit

Permalink
Merge pull request #416 from ipfs-shipyard/feat/custom-build-targets
Browse files Browse the repository at this point in the history
Support vendor-specific manifest.json
  • Loading branch information
lidel authored Mar 12, 2018
2 parents 5fad3c6 + 623786a commit d7435d4
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ add-on/dist
coverage
.nyc_output
add-on/ui-kit/**/*
add-on/manifest.json
25 changes: 0 additions & 25 deletions add-on/manifest.json → add-on/manifest.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
"38": "icons/png/ipfs-logo-on_38.png",
"128": "icons/png/ipfs-logo-on_128.png"
},
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "58.0"
}
},
"permissions": [
"<all_urls>",
"idle",
Expand All @@ -35,7 +29,6 @@
"page": "dist/background/background.html"
},
"browser_action": {
"browser_style": false,
"default_icon": {
"19": "icons/png/ipfs-logo-off_19.png",
"38": "icons/png/ipfs-logo-off_38.png",
Expand All @@ -45,7 +38,6 @@
"default_popup": "dist/popup/browser-action/index.html"
},
"options_ui": {
"browser_style": false,
"page": "dist/options/options.html"
},
"web_accessible_resources": [
Expand All @@ -64,23 +56,6 @@
"run_at": "document_start"
}
],
"protocol_handlers": [
{
"protocol": "web+dweb",
"name": "IPFS Add-On: DWEB protocol handler",
"uriTemplate": "https://ipfs.io/%s"
},
{
"protocol": "web+ipns",
"name": "IPFS Add-On: IPNS protocol handler",
"uriTemplate": "https://ipfs.io/%s"
},
{
"protocol": "web+ipfs",
"name": "IPFS Add-On: IPFS protocol handler",
"uriTemplate": "https://ipfs.io/%s"
}
],
"content_security_policy": "script-src 'self'; object-src 'self'; frame-src 'self';",
"default_locale": "en"
}
8 changes: 8 additions & 0 deletions add-on/manifest.firefox-beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"applications": {
"gecko": {
"id": "[email protected]",
"update_url": "https://ipfs-shipyard.github.io/ipfs-companion/ci/firefox/update.json"
}
}
}
31 changes: 31 additions & 0 deletions add-on/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"browser_action": {
"browser_style": false
},
"options_ui": {
"browser_style": false
},
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "58.0"
}
},
"protocol_handlers": [
{
"protocol": "web+dweb",
"name": "IPFS Add-On: DWEB protocol handler",
"uriTemplate": "https://ipfs.io/%s"
},
{
"protocol": "web+ipns",
"name": "IPFS Add-On: IPNS protocol handler",
"uriTemplate": "https://ipfs.io/%s"
},
{
"protocol": "web+ipfs",
"name": "IPFS Add-On: IPFS protocol handler",
"uriTemplate": "https://ipfs.io/%s"
}
]
}
2 changes: 1 addition & 1 deletion ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ node(label: 'linux') {
stage('ci:build') {
sh 'mkdir -p $(pwd)/build'
sh 'docker run -i --rm -v $(pwd)/build:/usr/src/app/build:rw -v $(pwd)/add-on:/usr/src/app/add-on:rw ipfs-companion:$(cat git-HEAD) npm run ci:build'
archiveArtifacts artifacts: 'build/*.zip', fingerprint: true
archiveArtifacts artifacts: 'build/**/*.zip', fingerprint: true
}
stage('lint:web-ext') {
sh 'docker run -i --rm -v $(pwd)/add-on:/usr/src/app/add-on:ro ipfs-companion:$(cat git-HEAD) npm run lint:web-ext'
Expand Down
18 changes: 1 addition & 17 deletions ci/update-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# to explicitly state that produced artifact is a dev build.
set -e

MANIFEST=add-on/manifest.json
MANIFEST=add-on/manifest.common.json

# restore original (make this script immutable)
git checkout $MANIFEST
Expand All @@ -28,19 +28,3 @@ NEW_COMMITS_IN_CURRENT_BRANCH=$(git rev-list --count HEAD ^refs/remotes/origin/m
BUILD_VERSION=$(($COMMITS_IN_MASTER*10+$NEW_COMMITS_IN_CURRENT_BRANCH))
set-manifest ".version = (.version + \".${BUILD_VERSION}\")"
grep \"version\" $MANIFEST

# addon-linter throws error on 'update_url' so it is disabled in dev build
# and needs to be manually opted-in when beta build is run
if [ "$1" == "firefox-beta" ]; then
# Switch to self-hosted dev-build for Firefox (https://github.com/ipfs-shipyard/ipfs-companion/issues/385)
DEV_BUILD_ADDON_ID="[email protected]"
UPDATE_URL="https://ipfs-shipyard.github.io/ipfs-companion/ci/firefox/update.json"

## Set ADD-ON ID
set-manifest ".applications.gecko[\"id\"] = \"$DEV_BUILD_ADDON_ID\""
grep ipfs-companion-dev-build $MANIFEST

## Add UPDATE_URL
set-manifest ".applications.gecko[\"update_url\"] = \"$UPDATE_URL\""
grep update_url $MANIFEST
fi
8 changes: 5 additions & 3 deletions docs/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ npm start # all-in-one

To do each step manually:
```bash
npm run build # build
npm run build # build runs bundle:firefox at the end, so manifest will be ok
npm run test # test suite
npm run firefox # spawn new Firefox
```
Expand All @@ -48,7 +48,7 @@ then click "Load Temporary Add-on" and point it at `add-on/manifest.json`
First, build it manually:

```bash
npm run build
npm run build bundle:generic # last part is important: it overwrites manifest
```

Then open up `chrome://extensions` in Chromium-based browser, enable "Developer mode", click "Load unpacked extension..." and point it at `add-on/manifest.json`
Expand All @@ -63,7 +63,9 @@ See [`docs/firefox-for-android.md`](firefox-for-android.md)
Each `npm` task can be run separately. The most useful ones are:

- `npm install` -- install all NPM dependencies
- `npm run build` -- build the add-on (copy external libraries, create `.zip` bundle)
- `npm run build` -- build the add-on (copy external libraries, create `.zip` bundles for Chrome and Firefox)
- `npm run bundle:generic` -- overwrites manifest and packages a Brave/Chrome-compatible version
- `npm run bundle:firefox` -- overwrites manifest and packages a Firefox-compatible version
- `npm run yarn-build` -- fast dependency install + build with yarn (installs and updates yarn.lock if needed)
- `npm run ci` -- reproducible test and build (with frozen yarn.lock)
- `npm test` -- run entire test suite
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
"build:content-scripts:ipfs-proxy:content": "browserify -p prundupify -g uglifyify -t brfs -t [ browserify-package-json --global ] -s IpfsProxyContent add-on/src/contentScripts/ipfs-proxy/content.js -o add-on/dist/contentScripts/ipfs-proxy/content.js",
"build:content-scripts:ipfs-proxy:cleanup": "shx rm add-on/dist/contentScripts/ipfs-proxy/page.js",
"build:minimize-dist": "shx rm -rf add-on/dist/lib",
"build:bundle-extension": "web-ext build -s add-on/ -i src/ -a build/",
"build:bundle-all": "run-s bundle:generic bundle:firefox",
"bundle": "run-s bundle:*",
"bundle:generic": "shx cp add-on/manifest.common.json add-on/manifest.json && web-ext build -a build/generic",
"bundle:firefox": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json | json --deep-merge > add-on/manifest.json && web-ext build -a build/firefox/",
"bundle:firefox:beta": "shx cat add-on/manifest.common.json add-on/manifest.firefox.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext build -a build/firefox/beta/",
"watch": "npm-run-all build:copy --parallel watch:*",
"watch:js": "watchify -p prundupify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js add-on/src/pages/proxy-acl/index.js add-on/src/pages/proxy-access-dialog/index.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js -o add-on/dist/pages/proxy-acl/proxy-acl.js -o add-on/dist/pages/proxy-access-dialog/proxy-access-dialog.js ] -o add-on/dist/ipfs-companion-common.js -v",
"watch:content-scripts": "run-p watch:content-scripts:*",
Expand All @@ -38,12 +42,12 @@
"test:functional": " nyc --reporter=lcov --reporter=text mocha --timeout 15000 --require ignore-styles --reporter mocha-jenkins-reporter 'test/functional/**/*.test.js'",
"lint": "run-s lint:*",
"lint:standard": "standard -v \"add-on/src/**/*.js\" \"test/**/*.js\"",
"lint:web-ext": "web-ext lint -s add-on/ -i src/",
"lint:web-ext": "web-ext lint",
"fix:lint": "run-s fix:lint:*",
"fix:lint:standard": "standard -v --fix \"add-on/src/**/*.js\" \"test/**/*.js\"",
"precommit": "run-s lint:standard",
"prepush": "run-s clean build lint test",
"firefox": "web-ext run -s add-on/ --browser-console",
"firefox": "web-ext run --browser-console",
"ci": "run-s ci:*",
"ci:install": "npx [email protected] install --frozen-lockfile || npx [email protected] install --frozen-lockfile",
"ci:test": "npx [email protected] test",
Expand All @@ -64,6 +68,7 @@
"geckodriver": "1.10.0",
"husky": "0.14.3",
"ignore-styles": "5.0.1",
"json": "9.0.6",
"mem-storage-area": "1.0.3",
"mocha": "5.0.1",
"mocha-jenkins-reporter": "0.3.10",
Expand Down
15 changes: 15 additions & 0 deletions web-ext-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext
module.exports = {
// Global options:
verbose: false,
artifactsDir: 'build/',
sourceDir: 'add-on/',
ignoreFiles: [
'src/',
'manifest.*.json',
],
// Command options:
build: {
overwriteDest: true,
}
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4907,6 +4907,10 @@ json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

[email protected]:
version "9.0.6"
resolved "https://registry.yarnpkg.com/json/-/json-9.0.6.tgz#7972c2a5a48a42678db2730c7c2c4ee6e4e24585"

jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
Expand Down

0 comments on commit d7435d4

Please sign in to comment.