From 6d941015677c799cff7cfb208a3a306b09435e5d Mon Sep 17 00:00:00 2001 From: Stefan Buck Date: Tue, 28 Jun 2016 00:24:31 +0200 Subject: [PATCH] Use npm script to build and pack extension (#107) * Use npm script to build and pack extension * Fix archive creation * Do not copy manifest file The manifest is already copied by the npm script task `chrome-manifest` --- .gitignore | 7 +------ {firefox => assets}/manifest.json | 0 chrome/manifest.json | 29 ----------------------------- package.json | 21 +++++++++++++-------- webpack.config.js | 6 ++++-- webpack.dist.config.js | 21 --------------------- 6 files changed, 18 insertions(+), 66 deletions(-) rename {firefox => assets}/manifest.json (100%) delete mode 100644 chrome/manifest.json delete mode 100644 webpack.dist.config.js diff --git a/.gitignore b/.gitignore index f8727225f5..0c7b3a2a34 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,4 @@ node_modules npm-debug.log dist/ - -chrome/* -!chrome/manifest.json - -firefox/* -!firefox/manifest.json +out/ diff --git a/firefox/manifest.json b/assets/manifest.json similarity index 100% rename from firefox/manifest.json rename to assets/manifest.json diff --git a/chrome/manifest.json b/chrome/manifest.json deleted file mode 100644 index 129fdaa43a..0000000000 --- a/chrome/manifest.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "OctoLinker", - "version": "4.1.0", - "manifest_version": 2, - "author": "Stefan Buck", - "description": "", - "homepage_url": "https://github.com/OctoLinker/browser-extension/", - "icons": { - "128": "icon.png" - }, - "background": { - "scripts": ["background.js"] - }, - "content_scripts": [ - { - "matches": [ - "https://github.com/*", - "https://gist.github.com/*" - ], - "js": ["app.js"], - "css": ["style.css"], - "run_at": "document_idle", - "all_frames": false - } - ], - "permissions": [ - "https://githublinker.herokuapp.com/" - ] -} diff --git a/package.json b/package.json index e9a2b61402..c4e201ec98 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,18 @@ "pretest": "npm run lint", "test": "karma start", "test:watch": "karma start --no-single-run --auto-watch", - "build": "webpack", - "build:watch": "webpack --watch", - "build-chrome": "webpack --output-path chrome", - "build-firefox": "webpack --output-path firefox", - "open-firefox": "web-ext run --source-dir firefox", - "dist-chrome": "webpack -p --config webpack.dist.config.js --dist=chrome", - "dist-firefox": "webpack -p --config webpack.dist.config.js --dist=firefox", - "dist-all": "npm run dist-chrome && npm run dist-firefox" + "chrome-manifest": "mkdir -p dist && json -e 'delete this.applications; this.permissions.shift()' < assets/manifest.json > dist/manifest.json", + "chrome-build": "npm run chrome-manifest && webpack", + "chrome-dist": "npm run chrome-build -- -p", + "chrome-watch": "npm run chrome-manifest && webpack --watch", + "chrome-pack": "npm run chrome-dist && mkdir -p out && zip -rj out/chrome-octolinker-$npm_package_version.zip dist", + "firefox-manifest": "mkdir -p dist && cp assets/manifest.json dist/manifest.json", + "firefox-build": "npm run firefox-manifest && webpack", + "firefox-dist": "npm run firefox-build -- -p", + "firefox-watch": "npm run firefox-manifest && webpack --watch", + "firefox-pack": "npm run firefox-dist && mkdir -p out && zip -rj out/firefox-octolinker-$npm_package_version.zip dist/", + "firefox-open": "npm run firefox-build && web-ext run --source-dir dist", + "pack-repo": "mkdir -p out && zip -r out/octolinker-repository-$npm_package_version.zip * --exclude dist/\\* out/\\* node_modules/\\*" }, "dependencies": { "JSONPath": "^0.11.2", @@ -41,6 +45,7 @@ "copy-webpack-plugin": "^3.0.1", "eslint": "^1.10.3", "eslint-config-airbnb": "2.1.1", + "json": "^9.0.4", "json-loader": "^0.5.4", "karma-fixture": "^0.2.5", "karma-html2js-preprocessor": "^0.1.0", diff --git a/webpack.config.js b/webpack.config.js index 66452609a5..b433b30a27 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,13 +7,15 @@ module.exports = { }, devtool: 'source-map', output: { - path: 'chrome', + path: 'dist', filename: '[name].js', }, plugins: [ new CopyWebpackPlugin([ { from: 'assets' }, - ]), + ], { + ignore: ['manifest.json'], + }), ], module: { loaders: [ diff --git a/webpack.dist.config.js b/webpack.dist.config.js deleted file mode 100644 index a35c36b9ff..0000000000 --- a/webpack.dist.config.js +++ /dev/null @@ -1,21 +0,0 @@ -const argv = require('yargs').argv; -const webpackConfig = require('./webpack.config.js'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); - -const dist = argv.dist; - -const config = Object.assign({}, webpackConfig, { - devtool: '', - output: { - path: `dist/${dist}`, - filename: '[name].js', - }, -}); - -config.plugins.push( - new CopyWebpackPlugin([ - { from: `${dist}/manifest.json` }, - ]) -); - -module.exports = config;