From ea35fe3c50cedf688e8ef88da55ca4c5d5986e97 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Tue, 21 Jun 2016 15:19:36 +0200 Subject: [PATCH] firefox extension support! --- .gitignore | 1 + extension/eventPage.js | 4 +++- extension/manifest.json | 2 +- gulpfile.babel.js | 42 ++++++++++++++++++++++++++++++++++++++++ package.json | 9 +++++---- pack.sh => packchrome.sh | 12 +++++------- 6 files changed, 57 insertions(+), 13 deletions(-) rename pack.sh => packchrome.sh (59%) diff --git a/.gitignore b/.gitignore index 16fbcdb..7cc8c04 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ extension/fimfic2epub.js extension.crx extension.pem +extension.xpi diff --git a/extension/eventPage.js b/extension/eventPage.js index dd196af..9ae2216 100644 --- a/extension/eventPage.js +++ b/extension/eventPage.js @@ -21,7 +21,9 @@ function fetch (url, cb, type) { x.send() } -chrome.extension.onMessage.addListener(function (request, sender, sendResponse) { +let onMessage = chrome.extension.onMessage ? chrome.extension.onMessage : chrome.runtime.onMessage + +onMessage.addListener(function (request, sender, sendResponse) { fetch(request, sendResponse, 'blob') return true }) diff --git a/extension/manifest.json b/extension/manifest.json index 576be3b..00cd387 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -3,7 +3,7 @@ "name": "fimfic2epub", "description": "", - "version": "1.0", + "version": "1.0.1", "background": { "scripts": ["eventPage.js"], diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 1f7fa93..7741b3d 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -9,6 +9,11 @@ import watch from 'gulp-watch' import lazypipe from 'lazypipe' import filter from 'gulp-filter' +import jsonedit from 'gulp-json-editor' +import zip from 'gulp-zip' + +import { execFile } from 'child_process' + // script import standard from 'gulp-standard' import webpack from 'webpack' @@ -95,3 +100,40 @@ gulp.task('default', (done) => { gulp.task('watch', (done) => { sequence('default', ['watch:lint', 'watch:webpack'], done) }) + +// creates extensions for chrome and firefox +gulp.task('pack', (done) => { + sequence('default', ['pack:firefox', 'pack:chrome'], done) +}) + +gulp.task('pack:firefox', () => { + let manifest = filter('extension/manifest.json', {restore: true}) + + return gulp.src('extension/**/*') + .pipe(manifest) + .pipe(jsonedit(function (json) { + if (json.content_scripts) { + json.applications = { + gecko: { + id: 'fimfic2epub@mozilla.org' + } + } + delete json.background.persistent + } + return json + })) + .pipe(manifest.restore) + .pipe(zip('extension.xpi')) + .pipe(gulp.dest('./')) +}) + +gulp.task('pack:chrome', (done) => { + execFile('./packchrome.sh', [], (error, stdout, stderr) => { + // gutil.log('[pack:chrome]', stdout) + if (error || stderr) { + done(new gutil.PluginError('pack:chrome', stderr, {showStack: false})) + return + } + done() + }) +}) diff --git a/package.json b/package.json index d642dee..61428fb 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "fimfic2epub.js", "private": true, - "version": "1.0.0", + "version": "1.0.1", "description": "", "author": "djazz", "scripts": { - "pack": "./pack.sh" + "pack": "gulp pack -p" }, "dependencies": { "escape-string-regexp": "^1.0.5", @@ -26,9 +26,11 @@ "exports-loader": "^0.6.3", "gulp": "^3.9.1", "gulp-filter": "^4.0.0", + "gulp-json-editor": "^2.2.1", "gulp-standard": "^7.0.1", "gulp-util": "^3.0.7", "gulp-watch": "^4.3.8", + "gulp-zip": "^3.2.0", "lazypipe": "^1.0.1", "raw-loader": "^0.5.1", "run-sequence": "^1.2.1", @@ -39,8 +41,7 @@ }, "standard": { "env": { - "browser": true, - "node": true + "browser": true } } } diff --git a/pack.sh b/packchrome.sh similarity index 59% rename from pack.sh rename to packchrome.sh index 6607047..78d1334 100755 --- a/pack.sh +++ b/packchrome.sh @@ -1,9 +1,5 @@ #!/bin/bash -PATH=node_modules/.bin:$PATH - -gulp -p - CHROME=`command -v chrome || command -v chromium` rm -f extension.crx @@ -11,15 +7,17 @@ rm -f extension.crx code=-1 if [ ! -f extension.pem ]; then - echo "Packing chrome extension and generating private key..." + echo "Packaging Chrome extension and generating private key..." "${CHROME}" --pack-extension=extension code=$? else - echo "Packing chrome extension with existing key..." + echo "Packaging Chrome extension with existing key..." "${CHROME}" --pack-extension=extension --pack-extension-key=extension.pem code=$? fi if [ ! -f extension.crx ]; then - echo "Something went wrong, Chrome error code ${code}" + >&2 echo "Something went wrong, Chrome error code ${code}" + exit $code fi +