Update build system

This commit is contained in:
daniel-j 2018-03-12 22:03:58 +01:00
parent 3efe5935d7
commit 592513dd47
9 changed files with 148 additions and 93 deletions

8
.gitignore vendored
View file

@ -1,13 +1,11 @@
.DS_Store .DS_Store
node_modules/ node_modules/
extension/fimfic2epub.js extension/build/
extension/eventPage.js
extension/*.js.map
extension.crx extension.crx
extension.pem extension.pem
extension.xpi extension.xpi
extension.zip extension.zip
fimfic2epub.safariextension/ fimfic2epub.safariextension/
fimfic2epub.js dist/
fimfic2epub.js.map build/
*.epub *.epub

View file

@ -1,13 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
// Fix for mithril // use a mock DOM so we can run mithril on the server
const noop = () => {} require('mithril/test-utils/browserMock')(global)
global.window = {
document: { createDocumentFragment: noop },
history: { pushState: noop }
}
const FimFic2Epub = require('../fimfic2epub') const FimFic2Epub = require('../dist/fimfic2epub')
const fs = require('fs') const fs = require('fs')
const STORY_ID = process.argv[2] const STORY_ID = process.argv[2]
@ -22,9 +18,11 @@ if (outputStdout) {
} }
ffc.on('progress', (percent, status) => { ffc.on('progress', (percent, status) => {
/*
if (status) { if (status) {
console.log('fimfic2epub: ' + status) console.log('fimfic2epub: ' + status)
} }
*/
}) })
ffc.fetchAll() ffc.fetchAll()

View file

@ -27,7 +27,7 @@
<dict> <dict>
<key>End</key> <key>End</key>
<array> <array>
<string>fimfic2epub.js</string> <string>build/fimfic2epub.js</string>
</array> </array>
</dict> </dict>
<key>Whitelist</key> <key>Whitelist</key>

View file

@ -1,10 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Background page</title> <title>fimfic2epub background page</title>
</head> </head>
<body> <body>
<script type="text/javascript" src="eventPage.js"></script> <script type="text/javascript" src="build/eventPage.js"></script>
</body> </body>
</html> </html>

View file

@ -4,21 +4,20 @@
"name": "fimfic2epub", "name": "fimfic2epub",
"short_name": "fimfic2epub", "short_name": "fimfic2epub",
"description": "Improved EPUB exporter for Fimfiction", "description": "Improved EPUB exporter for Fimfiction",
"version": "1.6.5",
"icons": { "icons": {
"128": "icon-128.png" "128": "icon-128.png"
}, },
"background": { "background": {
"scripts": ["eventPage.js"], "scripts": ["build/eventPage.js"],
"persistent": false "persistent": false
}, },
"content_scripts": [ "content_scripts": [
{ {
"matches": ["https://www.fimfiction.net/*", "http://www.fimfiction.net/*"], "matches": ["https://www.fimfiction.net/*", "http://www.fimfiction.net/*"],
"js": ["fimfic2epub.js"], "js": ["build/fimfic2epub.js"],
"css": ["inject.css"] "css": ["inject.css"]
} }
], ],

View file

@ -7,11 +7,14 @@ import Sequence from 'run-sequence'
import watch from 'gulp-watch' import watch from 'gulp-watch'
import lazypipe from 'lazypipe' import lazypipe from 'lazypipe'
import filter from 'gulp-filter' import filter from 'gulp-filter'
import merge from 'merge-stream'
import change from 'gulp-change'
import rename from 'gulp-rename'
import jsonedit from 'gulp-json-editor' import jsonedit from 'gulp-json-editor'
import zip from 'gulp-zip' import zip from 'gulp-zip'
import { execFile, exec } from 'child_process' // import { execFile, exec } from 'child_process'
// script // script
import standard from 'gulp-standard' import standard from 'gulp-standard'
@ -20,44 +23,33 @@ import webpackConfig from './webpack.config.babel.js'
const sequence = Sequence.use(gulp) const sequence = Sequence.use(gulp)
const inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1 // const inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
let watchOpts = { let watchOpts = {
readDelay: 500, readDelay: 500,
verbose: true verbose: true,
read: false
} }
webpackConfig.forEach((c) => { let packageVersion = require('./package.json').version
if (inProduction) {
c.plugins.push(new webpack.optimize.ModuleConcatenationPlugin()) let webpackDefines = new webpack.DefinePlugin({
c.plugins.push(new webpack.LoaderOptionsPlugin({ FIMFIC2EPUB_VERSION: JSON.stringify(packageVersion)
minimize: true,
debug: false
}))
/*
c.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true
},
comments: false,
mangle: {
screw_ie8: true
},
screw_ie8: true,
sourceMap: !!c.devtool
}))
*/
}
c.plugins.push(new webpack.DefinePlugin({
FIMFIC2EPUB_VERSION: JSON.stringify(require('./package.json').version)
}))
}) })
const wpCompiler = webpack(webpackConfig) webpackConfig.forEach((c) => {
c.plugins.push(webpackDefines)
})
let wpCompiler = webpack(webpackConfig)
function webpackTask (callback) { function webpackTask (callback) {
// run webpack if (webpackDefines.definitions.FIMFIC2EPUB_VERSION !== JSON.stringify(packageVersion)) {
webpackDefines.definitions.FIMFIC2EPUB_VERSION = JSON.stringify(packageVersion)
wpCompiler = webpack(webpackConfig)
}
// run webpack compiler
wpCompiler.run(function (err, stats) { wpCompiler.run(function (err, stats) {
if (err) throw new gutil.PluginError('webpack', err) if (err) throw new gutil.PluginError('webpack', err)
gutil.log('[webpack]', stats.toString({ gutil.log('[webpack]', stats.toString({
@ -71,6 +63,16 @@ function webpackTask (callback) {
}) })
} }
function convertFontAwesomeVars (contents) {
let vars = {}
let matchVar = /\$fa-var-(.*?): "\\(.*?)";/g
let ma
for (;(ma = matchVar.exec(contents));) {
vars[ma[1]] = String.fromCharCode(parseInt(ma[2], 16))
}
return JSON.stringify(vars)
}
let lintPipe = lazypipe() let lintPipe = lazypipe()
.pipe(filter, ['**/*', '!src/lib/**/*']) .pipe(filter, ['**/*', '!src/lib/**/*'])
.pipe(standard) .pipe(standard)
@ -78,21 +80,25 @@ let lintPipe = lazypipe()
// Cleanup task // Cleanup task
gulp.task('clean', () => del([ gulp.task('clean', () => del([
'extension/fimfic2epub.js', 'build/',
'extension/eventPage.js', 'extension/build/',
'extension/*.js.map', 'dist/',
'fimfic2epub.js',
'fimfic2epub.js.map',
'extension.zip', 'extension.zip',
'extension.xpi', 'extension.xpi',
'extension.crx', 'extension.crx',
'fimfic2epub.safariextension/' 'fimfic2epub.safariextension/'
])) ]))
gulp.task('version', (done) => {
delete require.cache[require.resolve('./package.json')]
packageVersion = require('./package.json').version
done()
})
// Main tasks // Main tasks
gulp.task('webpack', webpackTask) gulp.task('webpack', ['version', 'fontawesome'], webpackTask)
gulp.task('watch:webpack', () => { gulp.task('watch:webpack', () => {
return watch(['src/**/*.js', 'src/**/*.styl'], watchOpts, function () { return watch(['src/**/*.js', 'src/**/*.styl', './package.json'], watchOpts, () => {
return sequence('webpack') return sequence('webpack')
}) })
}) })
@ -101,8 +107,8 @@ gulp.task('lint', () => {
return gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js', 'bin/fimfic2epub']).pipe(lintPipe()) return gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js', 'bin/fimfic2epub']).pipe(lintPipe())
}) })
gulp.task('watch:lint', () => { gulp.task('watch:lint', () => {
return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.babel.js', 'bin/fimfic2epub'], watchOpts, function (file) { return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.babel.js', 'bin/fimfic2epub'], watchOpts, (file) => {
gulp.src(file.path).pipe(lintPipe()) return gulp.src(file.path).pipe(lintPipe())
}) })
}) })
@ -113,20 +119,38 @@ gulp.task('default', (done) => {
// Watch task // Watch task
gulp.task('watch', (done) => { gulp.task('watch', (done) => {
sequence('default', ['watch:lint', 'watch:webpack'], done) sequence('default', ['watch:lint', 'watch:pack', 'watch:webpack'], done)
}) })
// creates extensions for chrome and firefox gulp.task('fontawesome', () => {
let copy = gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.ttf')
.pipe(gulp.dest('extension/build/fonts/'))
let codes = gulp.src('node_modules/font-awesome/scss/_variables.scss')
.pipe(change(convertFontAwesomeVars))
.pipe(rename({
basename: 'font-awesome-codes',
extname: '.json',
dirname: ''
}))
.pipe(gulp.dest('build/'))
return merge(copy, codes)
})
gulp.task('pack', (done) => { gulp.task('pack', (done) => {
sequence(['pack:firefox', 'pack:chrome', 'pack:safari'], done) sequence(['pack:firefox', 'pack:chrome'], done)
})
gulp.task('watch:pack', () => {
return watch(['extension/**/*', '!extension/build/**/*'], watchOpts, () => {
return sequence('pack')
})
}) })
gulp.task('pack:firefox', () => { gulp.task('pack:firefox', ['version'], () => {
let manifest = filter('extension/manifest.json', {restore: true}) const manifest = filter('extension/manifest.json', {restore: true})
return gulp.src('extension/**/*') return gulp.src('extension/**/*')
.pipe(manifest) .pipe(manifest)
.pipe(jsonedit(function (json) { .pipe(jsonedit((json) => {
json.version = packageVersion
if (json.content_scripts) { if (json.content_scripts) {
// tweak the manifest so Firefox can read it // tweak the manifest so Firefox can read it
json.applications = { json.applications = {
@ -143,20 +167,23 @@ gulp.task('pack:firefox', () => {
.pipe(gulp.dest('./')) .pipe(gulp.dest('./'))
}) })
gulp.task('pack:chrome', (done) => { gulp.task('pack:chrome', ['version'], (done) => {
execFile('./packchrome.sh', [], (error, stdout, stderr) => { const manifest = filter('extension/manifest.json', {restore: true})
// gutil.log('[pack:chrome]', stdout)
if (error) { return gulp.src('extension/**/*')
done(new gutil.PluginError('pack:chrome', stderr, {showStack: false})) .pipe(manifest)
return .pipe(jsonedit({
} version: packageVersion
done() }))
}) .pipe(manifest.restore)
.pipe(zip('extension.zip'))
.pipe(gulp.dest('./'))
}) })
/*
gulp.task('pack:safari', (done) => { gulp.task('pack:safari', (done) => {
exec('rm -rf fimfic2epub.safariextension/; cp -r extension/ fimfic2epub.safariextension', [], (error, stdout, stderr) => { exec('rm -rf fimfic2epub.safariextension/; cp -r extension/ fimfic2epub.safariextension', [], (error, stdout, stderr) => {
// gutil.log('[pack:chrome]', stdout) // gutil.log('[pack:safari]', stdout)
if (error || stderr) { if (error || stderr) {
done(new gutil.PluginError('pack:safari', stderr, {showStack: false})) done(new gutil.PluginError('pack:safari', stderr, {showStack: false}))
return return
@ -164,3 +191,4 @@ gulp.task('pack:safari', (done) => {
done() done()
}) })
}) })
*/

View file

@ -8,15 +8,15 @@
"url": "https://github.com/daniel-j/fimfic2epub.git" "url": "https://github.com/daniel-j/fimfic2epub.git"
}, },
"scripts": { "scripts": {
"build": "gulp -p" "build": "NODE_ENV=production gulp",
"dev": "NODE_ENV=development gulp"
}, },
"bin": { "bin": {
"fimfic2epub": "./bin/fimfic2epub" "fimfic2epub": "./bin/fimfic2epub"
}, },
"main": "fimfic2epub.js", "main": "dist/fimfic2epub.js",
"files": [ "files": [
"fimfic2epub.js", "dist/",
"fimfic2epub.js.map",
"bin/" "bin/"
], ],
"dependencies": { "dependencies": {
@ -40,28 +40,33 @@
"devDependencies": { "devDependencies": {
"autosize": "^4.0.0", "autosize": "^4.0.0",
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
"babel-loader": "^7.1.2", "babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.14.0", "babel-preset-es2015": "^6.14.0",
"babel-preset-node6": "^11.0.0", "babel-preset-node6": "^11.0.0",
"babel-register": "^6.26.0", "babel-register": "^6.26.0",
"del": "^3.0.0", "del": "^3.0.0",
"es6-event-emitter": "^1.10.2", "es6-event-emitter": "^1.10.2",
"exports-loader": "^0.6.3", "exports-loader": "^0.7.0",
"file-saver": "^1.3.2", "file-saver": "^1.3.2",
"font-awesome": "4.7.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-change": "^1.0.0",
"gulp-filter": "^5.0.1", "gulp-filter": "^5.0.1",
"gulp-json-editor": "^2.2.1", "gulp-json-editor": "^2.2.1",
"gulp-rename": "^1.2.2",
"gulp-standard": "^10.1.1", "gulp-standard": "^10.1.1",
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"gulp-watch": "^4.3.9", "gulp-watch": "^5.0.0",
"gulp-zip": "^4.0.0", "gulp-zip": "^4.0.0",
"lazypipe": "^1.0.1", "lazypipe": "^1.0.1",
"merge-stream": "^1.0.1",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"run-sequence": "^2.2.0", "run-sequence": "^2.2.0",
"standard": "^10.0.3", "standard": "^11.0.0",
"stylus": "^0.54.5", "stylus": "^0.54.5",
"stylus-loader": "^3.0.1", "stylus-loader": "^3.0.1",
"webpack": "^3.8.1", "webpack": "^4.1.1",
"webpack-node-externals": "^1.3.3" "webpack-node-externals": "^1.3.3"
}, },
"standard": { "standard": {

View file

@ -4,7 +4,7 @@ CHROME=`command -v chrome || command -v chromium || command -v chromium-browser
rm -f extension.crx rm -f extension.crx
z=`cd extension && zip -Xr9D ../extension.zip .` # z=`cd extension && zip -Xr9D ../extension.zip .`
code=-1 code=-1

View file

@ -12,7 +12,7 @@ const bundleExtensionConfig = {
output: { output: {
path: path.join(__dirname, '/'), path: path.join(__dirname, '/'),
filename: './extension/[name].js' filename: './extension/build/[name].js'
}, },
module: { module: {
@ -38,16 +38,27 @@ const bundleExtensionConfig = {
modules: [ modules: [
path.resolve('./src'), path.resolve('./src'),
'node_modules' 'node_modules'
], ]
alias: { },
fs: require.resolve('./src/false.js')
} node: {
fs: 'empty'
}, },
externals: ['request'], externals: ['request'],
plugins: [], plugins: [
devtool: 'source-map' // new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)()
],
performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction
},
devtool: inProduction ? 'nosources-source-map' : 'source-map',
mode: inProduction ? 'production' : 'development'
} }
const bundleNpmModuleConfig = { const bundleNpmModuleConfig = {
@ -55,7 +66,7 @@ const bundleNpmModuleConfig = {
output: { output: {
path: path.join(__dirname, '/'), path: path.join(__dirname, '/'),
filename: './fimfic2epub.js', filename: './dist/fimfic2epub.js',
libraryTarget: 'commonjs2' libraryTarget: 'commonjs2'
}, },
@ -69,7 +80,11 @@ const bundleNpmModuleConfig = {
exclude: /node_modules/, exclude: /node_modules/,
query: { query: {
sourceMaps: !inProduction, sourceMaps: !inProduction,
presets: ['es2015'] presets: [['env', {
targets: {
node: '8.0.0'
}
}]]
} }
}, },
{ {
@ -87,10 +102,22 @@ const bundleNpmModuleConfig = {
] ]
}, },
node: {
__dirname: false
},
externals: [nodeExternals({whitelist: ['es6-event-emitter', /^babel-runtime/]})], externals: [nodeExternals({whitelist: ['es6-event-emitter', /^babel-runtime/]})],
plugins: [], plugins: [],
devtool: 'source-map' performance: {
hints: false
},
optimization: {
concatenateModules: inProduction,
minimize: inProduction
},
devtool: 'nosources-source-map',
mode: inProduction ? 'production' : 'development'
} }
export default [bundleExtensionConfig, bundleNpmModuleConfig] export default [bundleExtensionConfig, bundleNpmModuleConfig]