From a6af70e53ac3a08800d11127d5128fbf33e88db1 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Wed, 10 Apr 2019 15:31:29 +0200 Subject: [PATCH] update packages, gulp and webpack config updates, mimetype fix --- .babelrc | 2 +- gulpfile.babel.js | 166 +++++++++++++++++++--------------------- package.json | 52 ++++++------- src/FimFic2Epub.js | 6 +- src/cli.js | 2 +- src/main.js | 14 +++- src/styles.js | 21 +++-- webpack.config.babel.js | 79 ++++++++++--------- 8 files changed, 173 insertions(+), 169 deletions(-) diff --git a/.babelrc b/.babelrc index a0f53ac..c5745e3 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,5 @@ { - "presets": [['env', { + "presets": [['@babel/env', { "targets": { "node": "current" } diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 2035ea3..98d7005 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -3,9 +3,7 @@ import gulp from 'gulp' import gutil from 'gulp-util' import del from 'del' -import Sequence from 'run-sequence' import watch from 'gulp-watch' -import lazypipe from 'lazypipe' import filter from 'gulp-filter' import change from 'gulp-change' import rename from 'gulp-rename' @@ -23,8 +21,6 @@ import standard from 'gulp-standard' import webpack from 'webpack' import webpackConfig from './webpack.config.babel.js' -const sequence = Sequence.use(gulp) - const inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1 const isStandalone = process.argv.includes('--standalone') @@ -59,39 +55,37 @@ webpackConfig.forEach((c) => { let wpCompiler = webpack(webpackConfig) -function webpackTask (callback) { - if (webpackDefines.definitions.FIMFIC2EPUB_VERSION !== JSON.stringify(packageVersion)) { - webpackDefines.definitions.FIMFIC2EPUB_VERSION = JSON.stringify(packageVersion) - wpCompiler = webpack(webpackConfig) - } +function webpackTask () { + return new Promise((resolve, reject) => { + if (webpackDefines.definitions.FIMFIC2EPUB_VERSION !== JSON.stringify(packageVersion)) { + webpackDefines.definitions.FIMFIC2EPUB_VERSION = JSON.stringify(packageVersion) + wpCompiler = webpack(webpackConfig) + } - let p = Promise.resolve() - if (inProduction) { - p = removeNPMAbsolutePaths('node_modules') - } + let p = Promise.resolve() + if (inProduction) { + p = removeNPMAbsolutePaths('node_modules') + } - p.then((results) => { - // run webpack compiler - wpCompiler.run(function (err, stats) { - if (err) throw new gutil.PluginError('webpack', err) - gutil.log('[webpack]', stats.toString({ - colors: true, - hash: false, - version: false, - chunks: false, - timings: false, - modules: false, - chunkModules: false, - cached: false, - maxModules: 0 - })) - if (!isStandalone) { - sequence('pack', callback) - } else { - sequence('binaries', callback) - } - }) - }).catch((err) => { throw err }) + p.then((results) => { + // run webpack compiler + wpCompiler.run(function (err, stats) { + if (err) throw new gutil.PluginError('webpack', err) + gutil.log('[webpack]', stats.toString({ + colors: true, + hash: false, + version: false, + chunks: false, + timings: false, + modules: false, + chunkModules: false, + cached: false, + maxModules: 0 + })) + resolve() + }) + }).catch((err) => { throw err }) + }) } function convertFontAwesomeVars (contents) { @@ -104,10 +98,12 @@ function convertFontAwesomeVars (contents) { return JSON.stringify(vars) } -let lintPipe = lazypipe() - .pipe(filter, ['**/*', '!src/lib/**/*']) - .pipe(standard) - .pipe(standard.reporter, 'default', { breakOnError: false }) +function lintPipe (stream) { + return stream + .pipe(filter(['**/*', '!src/lib/**/*'])) + .pipe(standard()) + .pipe(standard.reporter('default', { breakOnError: false })) +} // Cleanup task gulp.task('clean', () => del([ @@ -121,46 +117,11 @@ gulp.task('clean', () => del([ 'fimfic2epub.safariextension/' ])) -gulp.task('version', (done) => { +gulp.task('version', () => { delete require.cache[require.resolve('./package.json')] packageVersion = require('./package.json').version - done() + return Promise.resolve() }) - -// Main tasks -gulp.task('webpack', ['version', 'fontawesome'], webpackTask) -gulp.task('binaries', ['version'], () => { - return gulp.src(['build/fimfic2epub.js', 'build/fimfic2epub-static.js']) - .pipe(rename({ extname: '' })) - .pipe(banner('#!/usr/bin/env node\n// fimfic2epub ' + packageVersion + '\n')) - .pipe(chmod(0o777)) - .pipe(gulp.dest('bin/')) -}) -gulp.task('watch:webpack', () => { - return watch(['src/**/*.js', 'src/**/*.styl', './package.json'], watchOpts, () => { - return sequence('webpack') - }) -}) - -gulp.task('lint', () => { - return gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js']).pipe(lintPipe()) -}) -gulp.task('watch:lint', () => { - return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.babel.js'], watchOpts, (file) => { - return gulp.src(file.path).pipe(lintPipe()) - }) -}) - -// Default task -gulp.task('default', (done) => { - sequence('clean', ['webpack', 'lint'], done) -}) - -// Watch task -gulp.task('watch', (done) => { - sequence('default', ['watch:lint', 'watch:pack', 'watch:webpack'], done) -}) - gulp.task('fontawesome', () => { return gulp.src('node_modules/font-awesome/scss/_variables.scss') .pipe(change(convertFontAwesomeVars)) @@ -171,17 +132,17 @@ gulp.task('fontawesome', () => { })) .pipe(gulp.dest('build/')) }) -gulp.task('pack', ['binaries'], (done) => { - sequence(['pack:firefox', 'pack:chrome'], done) -}) -gulp.task('watch:pack', () => { - return watch(['extension/**/*', '!extension/build/**/*'], watchOpts, () => { - return sequence('pack') - }) -}) -gulp.task('pack:firefox', ['version'], () => { - const manifest = filter('extension/manifest.json', {restore: true}) +gulp.task('binaries', gulp.series('version', function binariesTask () { + return gulp.src(['build/fimfic2epub.js', 'build/fimfic2epub-static.js']) + .pipe(rename({ extname: '' })) + .pipe(banner('#!/usr/bin/env node\n// fimfic2epub ' + packageVersion + '\n')) + .pipe(chmod(0o777)) + .pipe(gulp.dest('bin/')) +})) + +gulp.task('pack:firefox', gulp.series('version', function packFirefox () { + const manifest = filter('extension/manifest.json', { restore: true }) return gulp.src('extension/**/*') .pipe(manifest) @@ -201,10 +162,10 @@ gulp.task('pack:firefox', ['version'], () => { .pipe(manifest.restore) .pipe(zip('extension.xpi')) .pipe(gulp.dest('./')) -}) +})) -gulp.task('pack:chrome', ['version'], (done) => { - const manifest = filter('extension/manifest.json', {restore: true}) +gulp.task('pack:chrome', gulp.series('version', function packChrome () { + const manifest = filter('extension/manifest.json', { restore: true }) return gulp.src('extension/**/*') .pipe(manifest) @@ -214,8 +175,35 @@ gulp.task('pack:chrome', ['version'], (done) => { .pipe(manifest.restore) .pipe(zip('extension.zip')) .pipe(gulp.dest('./')) +})) +gulp.task('pack', gulp.parallel('pack:firefox', 'pack:chrome')) + +// Main tasks +gulp.task('webpack', gulp.series(gulp.parallel('version', 'fontawesome'), webpackTask, isStandalone ? 'binaries' : 'pack')) + +gulp.task('watch:webpack', () => { + return watch(['src/**/*.js', 'src/**/*.styl', './package.json'], watchOpts, gulp.series('webpack')) }) +gulp.task('lint', () => { + return lintPipe(gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js'])) +}) +gulp.task('watch:lint', () => { + return watch(['src/**/*.js', 'gulpfile.babel.js', 'webpack.config.babel.js'], watchOpts, (file) => { + return lintPipe(gulp.src(file.path)) + }) +}) + +// Default task +gulp.task('default', gulp.series('clean', gulp.parallel('webpack', 'lint'))) + +gulp.task('watch:pack', () => { + return watch(['extension/**/*', '!extension/build/**/*'], watchOpts, gulp.series('pack')) +}) + +// Watch task +gulp.task('watch', gulp.series('default', gulp.parallel('watch:lint', 'watch:pack', 'watch:webpack'))) + /* gulp.task('pack:safari', (done) => { exec('rm -rf fimfic2epub.safariextension/; cp -r extension/ fimfic2epub.safariextension', [], (error, stdout, stderr) => { diff --git a/package.json b/package.json index 5443622..f68e072 100644 --- a/package.json +++ b/package.json @@ -22,64 +22,62 @@ "LICENSE" ], "dependencies": { - "commander": "^2.19.0", + "commander": "^2.20.0", "crc-32": "^1.2.0", "detect-node": "^2.0.4", "elementtree": "^0.1.7", "escape-string-regexp": "^1.0.5", - "file-type": "^8.1.0", + "file-type": "^10.10.0", "fonteditor-core": "^1.0.5", "html-entities": "^1.2.1", - "html-to-text": "^4.0.0", - "image-size": "^0.6.3", - "is-svg": "^3.0.0", - "jszip": "^3.1.5", + "html-to-text": "^5.1.1", + "image-size": "^0.7.3", + "is-svg": "^4.1.0", + "jszip": "^3.2.1", "match-words": "^1.0.0", "mithril": "^1.1.6", - "mithril-node-render": "^2.3.0", + "mithril-node-render": "^2.3.2", "node-png": "^0.4.3", "pretty-data": "^0.40.0", "request": "^2.88.0", "sanitize-filename": "^1.6.1", - "syllable": "^3.1.0", - "twemoji": "^11.0.1", + "syllable": "^3.5.0", + "twemoji": "^12.0.0", "typogr": "^0.6.8", "url-regex": "^4.1.1", "zero-fill": "^2.2.3" }, "devDependencies": { + "@babel/core": "^7.4.3", + "@babel/preset-env": "^7.4.3", + "@babel/register": "^7.4.0", "autosize": "^4.0.2", - "babel-core": "^6.26.3", - "babel-loader": "^7.1.5", - "babel-preset-env": "^1.7.0", - "babel-register": "^6.26.0", + "babel-loader": "^8.0.5", "binary-loader": "0.0.1", - "del": "^3.0.0", - "eslint": "^5.6.1", - "eslint-plugin-standard": "^3.1.0", + "del": "^4.1.0", + "eslint": "^5.16.0", + "eslint-plugin-standard": "^4.0.0", "exports-loader": "^0.7.0", - "file-saver": "^1.3.8", + "file-saver": "^2.0.1", "font-awesome": "4.7.0", - "gulp": "^3.9.1", + "gulp": "^4.0.0", "gulp-banner": "^0.1.3", - "gulp-change": "^1.0.0", + "gulp-change": "^1.0.2", "gulp-chmod": "^2.0.0", "gulp-filter": "^5.1.0", - "gulp-json-editor": "^2.4.2", + "gulp-json-editor": "^2.5.1", "gulp-rename": "^1.4.0", - "gulp-standard": "^11.0.0", + "gulp-standard": "^12.0.0", "gulp-util": "^3.0.8", "gulp-watch": "^5.0.1", "gulp-zip": "^4.2.0", - "lazypipe": "^1.0.1", - "raw-loader": "^0.5.1", - "regenerator-runtime": "^0.12.1", + "raw-loader": "^2.0.0", + "regenerator-runtime": "^0.13.2", "removeNPMAbsolutePaths": "^1.0.4", - "run-sequence": "^2.2.1", - "standard": "^11.0.1", + "standard": "^12.0.1", "stylus": "^0.54.5", "stylus-loader": "^3.0.2", - "webpack": "^4.20.2", + "webpack": "^4.29.6", "webpack-node-externals": "^1.7.2" }, "standard": { diff --git a/src/FimFic2Epub.js b/src/FimFic2Epub.js index 1848125..82aecd5 100644 --- a/src/FimFic2Epub.js +++ b/src/FimFic2Epub.js @@ -466,7 +466,7 @@ class FimFic2Epub extends EventEmitter { this.zip = new JSZip() - this.zip.file('mimetype', 'application/epub+zip') + this.zip.file('mimetype', 'application/epub+zip', {compression: 'STORE'}) this.zip.file('META-INF/container.xml', containerXml) this.zip.file('OEBPS/content.opf', Buffer.from(await template.createOpf(this), 'utf8')) @@ -591,7 +591,7 @@ class FimFic2Epub extends EventEmitter { this.filename = FimFic2Epub.getFilename(this.storyInfo) } setCoverImage (buffer) { - buffer = isNode ? buffer : new Uint8Array(buffer) + buffer = isNode ? buffer : Buffer.from(new Uint8Array(buffer)) let info = fileType(buffer) if (!info || !info.mime.startsWith('image/')) { throw new Error('Invalid image') @@ -869,4 +869,4 @@ class FimFic2Epub extends EventEmitter { } } -module.exports = FimFic2Epub +export default FimFic2Epub diff --git a/src/cli.js b/src/cli.js index 71b28c4..643a09c 100755 --- a/src/cli.js +++ b/src/cli.js @@ -39,7 +39,7 @@ if (outputStdout) { require('mithril/test-utils/browserMock')(global) const htmlToText = require('./utils').htmlToText -const FimFic2Epub = require('./FimFic2Epub') +const FimFic2Epub = require('./FimFic2Epub').default const fs = require('fs') const path = require('path') diff --git a/src/main.js b/src/main.js index 825bf67..7ad7d8b 100644 --- a/src/main.js +++ b/src/main.js @@ -167,8 +167,12 @@ let dialog = { } this.setCoverFile = (e) => { - this.coverUrl('') - this.coverFile(e.target.files ? e.target.files[0] : null) + let el = e.dom || e.target + if (el.target) { + this.coverUrl('') + } + this.coverFile(el.files ? el.files[0] : null) + console.log('files:', el.files) } this.setSubjects = function () { @@ -243,7 +247,7 @@ let dialog = { m('tr', m('td.label', 'Author'), m('td', {colspan: 2}, m('input', {type: 'text', value: ctrl.author(), onchange: m.withAttr('value', ctrl.author)}))), m('tr', m('td.label', 'Custom cover image'), m('td', - ctrl.checkboxCoverUrl() ? m('input', {type: 'url', placeholder: 'Image URL', onchange: m.withAttr('value', ctrl.coverUrl)}) : m('input', {type: 'file', accept: 'image/*', onchange: ctrl.setCoverFile}) + ctrl.checkboxCoverUrl() ? m('input', {type: 'url', placeholder: 'Image URL', onchange: m.withAttr('value', ctrl.coverUrl)}) : m('input', {type: 'file', accept: 'image/*', onchange: ctrl.setCoverFile, onupdate: ctrl.setCoverFile}) ), m('td', {style: 'width: 1px'}, m(checkbox, {checked: ctrl.checkboxCoverUrl(), onchange: m.withAttr('checked', ctrl.checkboxCoverUrl)}, 'Use image URL')) ), @@ -320,7 +324,9 @@ function createEpub (model) { } else if (model.coverFile()) { chain = chain .then(() => blobToArrayBuffer(model.coverFile())) - .then(ffc.setCoverImage.bind(ffc)) + .then((buf) => { + ffc.setCoverImage(buf) + }).catch((err) => console.error(err)) } ffc.setTitle(model.title()) diff --git a/src/styles.js b/src/styles.js index 2da1757..2a4654e 100644 --- a/src/styles.js +++ b/src/styles.js @@ -1,13 +1,18 @@ -const styleCss = require('./style/style') -const coverstyleCss = require('./style/coverstyle') -const titlestyleCss = require('./style/titlestyle') -const navstyleCss = require('./style/navstyle') -const iconsCss = require('./style/icons') +import styleCss from './style/style' +import coverstyleCss from './style/coverstyle' +import titlestyleCss from './style/titlestyle' +import navstyleCss from './style/navstyle' +import iconsCss from './style/icons' + +import paragraphsSpaced from './style/paragraphs-spaced' +import paragraphsIndented from './style/paragraphs-indented' +import paragraphsIndentAll from './style/paragraphs-indentedall' + const paragraphsCss = { - spaced: require('./style/paragraphs-spaced'), - indented: require('./style/paragraphs-indented'), - indentedall: require('./style/paragraphs-indentedall') + spaced: paragraphsSpaced, + indented: paragraphsIndented, + indentedall: paragraphsIndentAll } paragraphsCss.both = paragraphsCss.indented + '\n' + paragraphsCss.spaced diff --git a/webpack.config.babel.js b/webpack.config.babel.js index a6bf1dc..f333398 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -19,16 +19,17 @@ const bundleExtensionConfig = { rules: [ { test: /\.js$/, - loader: 'babel-loader', exclude: /node_modules/, - query: { - presets: [['env', { - targets: { - browsers: ['chrome 50', 'firefox 47'] - }, - modules: false, - useBuiltIns: true - }]] + use: { + loader: 'babel-loader', + options: { + presets: [['@babel/env', { + targets: { + browsers: ['chrome 50', 'firefox 47'] + }, + modules: false + }]] + } } }, { @@ -85,15 +86,17 @@ const bundleNpmModuleConfig = { rules: [ { test: /\.js$/, - loader: 'babel-loader', exclude: /node_modules/, - query: { - sourceMaps: !inProduction, - presets: [['env', { - targets: { - node: '8.0.0' - } - }]] + use: { + loader: 'babel-loader', + options: { + sourceMaps: !inProduction, + presets: [['@babel/env', { + targets: { + node: '8.0.0' + } + }]] + } } }, { @@ -108,7 +111,7 @@ const bundleNpmModuleConfig = { }, resolve: { - extensions: ['.js', '.json', '.styl'], + extensions: ['.js', '.json', '.styl', '.node'], modules: [ path.resolve('./src'), 'node_modules' @@ -147,22 +150,24 @@ const bundleNpmBinaryConfig = { rules: [ { test: /\.js$/, - loader: 'babel-loader', exclude: /node_modules/, - query: { - sourceMaps: !inProduction, - presets: [['env', { - targets: { - node: '8.0.0' - } - }]] + use: { + loader: 'babel-loader', + options: { + sourceMaps: !inProduction, + presets: [['@babel/env', { + targets: { + node: '8.0.0' + } + }]] + } } } ] }, resolve: { - extensions: ['.js', '.json'], + extensions: ['.js', '.json', '.node'], modules: [ path.resolve('./src'), 'node_modules' @@ -204,15 +209,17 @@ const bundleStaticNpmModuleConfig = { rules: [ { test: /\.js$/, - loader: 'babel-loader', exclude: /node_modules/, - query: { - sourceMaps: !inProduction, - presets: [['env', { - targets: { - node: 'current' - } - }]] + use: { + loader: 'babel-loader', + options: { + sourceMaps: !inProduction, + presets: [['@babel/env', { + targets: { + node: 'current' + } + }]] + } } }, { @@ -227,7 +234,7 @@ const bundleStaticNpmModuleConfig = { }, resolve: { - extensions: ['.js', '.json', '.styl'], + extensions: ['.js', '.json', '.styl', '.node'], modules: [ path.resolve('./bin'), 'node_modules'