Skip to content

Commit

Permalink
firefox extension support!
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j committed Jun 21, 2016
1 parent 0587849 commit ea35fe3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
extension/fimfic2epub.js
extension.crx
extension.pem
extension.xpi
4 changes: 3 additions & 1 deletion extension/eventPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "fimfic2epub",
"description": "",
"version": "1.0",
"version": "1.0.1",

"background": {
"scripts": ["eventPage.js"],
Expand Down
42 changes: 42 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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: '[email protected]'
}
}
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()
})
})
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -39,8 +41,7 @@
},
"standard": {
"env": {
"browser": true,
"node": true
"browser": true
}
}
}
12 changes: 5 additions & 7 deletions pack.sh → packchrome.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#!/bin/bash

PATH=node_modules/.bin:$PATH

gulp -p

CHROME=`command -v chrome || command -v chromium`

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

0 comments on commit ea35fe3

Please sign in to comment.