update packages, gulp and webpack config updates, mimetype fix

This commit is contained in:
daniel-j 2019-04-10 15:31:29 +02:00
parent b9d66d9d40
commit a6af70e53a
8 changed files with 173 additions and 169 deletions

View file

@ -1,5 +1,5 @@
{ {
"presets": [['env', { "presets": [['@babel/env', {
"targets": { "targets": {
"node": "current" "node": "current"
} }

View file

@ -3,9 +3,7 @@
import gulp from 'gulp' import gulp from 'gulp'
import gutil from 'gulp-util' import gutil from 'gulp-util'
import del from 'del' import del from 'del'
import Sequence from 'run-sequence'
import watch from 'gulp-watch' import watch from 'gulp-watch'
import lazypipe from 'lazypipe'
import filter from 'gulp-filter' import filter from 'gulp-filter'
import change from 'gulp-change' import change from 'gulp-change'
import rename from 'gulp-rename' import rename from 'gulp-rename'
@ -23,8 +21,6 @@ import standard from 'gulp-standard'
import webpack from 'webpack' import webpack from 'webpack'
import webpackConfig from './webpack.config.babel.js' 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 inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
const isStandalone = process.argv.includes('--standalone') const isStandalone = process.argv.includes('--standalone')
@ -59,39 +55,37 @@ webpackConfig.forEach((c) => {
let wpCompiler = webpack(webpackConfig) let wpCompiler = webpack(webpackConfig)
function webpackTask (callback) { function webpackTask () {
if (webpackDefines.definitions.FIMFIC2EPUB_VERSION !== JSON.stringify(packageVersion)) { return new Promise((resolve, reject) => {
webpackDefines.definitions.FIMFIC2EPUB_VERSION = JSON.stringify(packageVersion) if (webpackDefines.definitions.FIMFIC2EPUB_VERSION !== JSON.stringify(packageVersion)) {
wpCompiler = webpack(webpackConfig) webpackDefines.definitions.FIMFIC2EPUB_VERSION = JSON.stringify(packageVersion)
} wpCompiler = webpack(webpackConfig)
}
let p = Promise.resolve() let p = Promise.resolve()
if (inProduction) { if (inProduction) {
p = removeNPMAbsolutePaths('node_modules') p = removeNPMAbsolutePaths('node_modules')
} }
p.then((results) => { p.then((results) => {
// run webpack compiler // 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({
colors: true, colors: true,
hash: false, hash: false,
version: false, version: false,
chunks: false, chunks: false,
timings: false, timings: false,
modules: false, modules: false,
chunkModules: false, chunkModules: false,
cached: false, cached: false,
maxModules: 0 maxModules: 0
})) }))
if (!isStandalone) { resolve()
sequence('pack', callback) })
} else { }).catch((err) => { throw err })
sequence('binaries', callback) })
}
})
}).catch((err) => { throw err })
} }
function convertFontAwesomeVars (contents) { function convertFontAwesomeVars (contents) {
@ -104,10 +98,12 @@ function convertFontAwesomeVars (contents) {
return JSON.stringify(vars) return JSON.stringify(vars)
} }
let lintPipe = lazypipe() function lintPipe (stream) {
.pipe(filter, ['**/*', '!src/lib/**/*']) return stream
.pipe(standard) .pipe(filter(['**/*', '!src/lib/**/*']))
.pipe(standard.reporter, 'default', { breakOnError: false }) .pipe(standard())
.pipe(standard.reporter('default', { breakOnError: false }))
}
// Cleanup task // Cleanup task
gulp.task('clean', () => del([ gulp.task('clean', () => del([
@ -121,46 +117,11 @@ gulp.task('clean', () => del([
'fimfic2epub.safariextension/' 'fimfic2epub.safariextension/'
])) ]))
gulp.task('version', (done) => { gulp.task('version', () => {
delete require.cache[require.resolve('./package.json')] delete require.cache[require.resolve('./package.json')]
packageVersion = require('./package.json').version 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', () => { gulp.task('fontawesome', () => {
return gulp.src('node_modules/font-awesome/scss/_variables.scss') return gulp.src('node_modules/font-awesome/scss/_variables.scss')
.pipe(change(convertFontAwesomeVars)) .pipe(change(convertFontAwesomeVars))
@ -171,17 +132,17 @@ gulp.task('fontawesome', () => {
})) }))
.pipe(gulp.dest('build/')) .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'], () => { gulp.task('binaries', gulp.series('version', function binariesTask () {
const manifest = filter('extension/manifest.json', {restore: true}) 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/**/*') return gulp.src('extension/**/*')
.pipe(manifest) .pipe(manifest)
@ -201,10 +162,10 @@ gulp.task('pack:firefox', ['version'], () => {
.pipe(manifest.restore) .pipe(manifest.restore)
.pipe(zip('extension.xpi')) .pipe(zip('extension.xpi'))
.pipe(gulp.dest('./')) .pipe(gulp.dest('./'))
}) }))
gulp.task('pack:chrome', ['version'], (done) => { gulp.task('pack:chrome', gulp.series('version', function packChrome () {
const 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)
@ -214,8 +175,35 @@ gulp.task('pack:chrome', ['version'], (done) => {
.pipe(manifest.restore) .pipe(manifest.restore)
.pipe(zip('extension.zip')) .pipe(zip('extension.zip'))
.pipe(gulp.dest('./')) .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) => { 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) => {

View file

@ -22,64 +22,62 @@
"LICENSE" "LICENSE"
], ],
"dependencies": { "dependencies": {
"commander": "^2.19.0", "commander": "^2.20.0",
"crc-32": "^1.2.0", "crc-32": "^1.2.0",
"detect-node": "^2.0.4", "detect-node": "^2.0.4",
"elementtree": "^0.1.7", "elementtree": "^0.1.7",
"escape-string-regexp": "^1.0.5", "escape-string-regexp": "^1.0.5",
"file-type": "^8.1.0", "file-type": "^10.10.0",
"fonteditor-core": "^1.0.5", "fonteditor-core": "^1.0.5",
"html-entities": "^1.2.1", "html-entities": "^1.2.1",
"html-to-text": "^4.0.0", "html-to-text": "^5.1.1",
"image-size": "^0.6.3", "image-size": "^0.7.3",
"is-svg": "^3.0.0", "is-svg": "^4.1.0",
"jszip": "^3.1.5", "jszip": "^3.2.1",
"match-words": "^1.0.0", "match-words": "^1.0.0",
"mithril": "^1.1.6", "mithril": "^1.1.6",
"mithril-node-render": "^2.3.0", "mithril-node-render": "^2.3.2",
"node-png": "^0.4.3", "node-png": "^0.4.3",
"pretty-data": "^0.40.0", "pretty-data": "^0.40.0",
"request": "^2.88.0", "request": "^2.88.0",
"sanitize-filename": "^1.6.1", "sanitize-filename": "^1.6.1",
"syllable": "^3.1.0", "syllable": "^3.5.0",
"twemoji": "^11.0.1", "twemoji": "^12.0.0",
"typogr": "^0.6.8", "typogr": "^0.6.8",
"url-regex": "^4.1.1", "url-regex": "^4.1.1",
"zero-fill": "^2.2.3" "zero-fill": "^2.2.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/register": "^7.4.0",
"autosize": "^4.0.2", "autosize": "^4.0.2",
"babel-core": "^6.26.3", "babel-loader": "^8.0.5",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"binary-loader": "0.0.1", "binary-loader": "0.0.1",
"del": "^3.0.0", "del": "^4.1.0",
"eslint": "^5.6.1", "eslint": "^5.16.0",
"eslint-plugin-standard": "^3.1.0", "eslint-plugin-standard": "^4.0.0",
"exports-loader": "^0.7.0", "exports-loader": "^0.7.0",
"file-saver": "^1.3.8", "file-saver": "^2.0.1",
"font-awesome": "4.7.0", "font-awesome": "4.7.0",
"gulp": "^3.9.1", "gulp": "^4.0.0",
"gulp-banner": "^0.1.3", "gulp-banner": "^0.1.3",
"gulp-change": "^1.0.0", "gulp-change": "^1.0.2",
"gulp-chmod": "^2.0.0", "gulp-chmod": "^2.0.0",
"gulp-filter": "^5.1.0", "gulp-filter": "^5.1.0",
"gulp-json-editor": "^2.4.2", "gulp-json-editor": "^2.5.1",
"gulp-rename": "^1.4.0", "gulp-rename": "^1.4.0",
"gulp-standard": "^11.0.0", "gulp-standard": "^12.0.0",
"gulp-util": "^3.0.8", "gulp-util": "^3.0.8",
"gulp-watch": "^5.0.1", "gulp-watch": "^5.0.1",
"gulp-zip": "^4.2.0", "gulp-zip": "^4.2.0",
"lazypipe": "^1.0.1", "raw-loader": "^2.0.0",
"raw-loader": "^0.5.1", "regenerator-runtime": "^0.13.2",
"regenerator-runtime": "^0.12.1",
"removeNPMAbsolutePaths": "^1.0.4", "removeNPMAbsolutePaths": "^1.0.4",
"run-sequence": "^2.2.1", "standard": "^12.0.1",
"standard": "^11.0.1",
"stylus": "^0.54.5", "stylus": "^0.54.5",
"stylus-loader": "^3.0.2", "stylus-loader": "^3.0.2",
"webpack": "^4.20.2", "webpack": "^4.29.6",
"webpack-node-externals": "^1.7.2" "webpack-node-externals": "^1.7.2"
}, },
"standard": { "standard": {

View file

@ -466,7 +466,7 @@ class FimFic2Epub extends EventEmitter {
this.zip = new JSZip() 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('META-INF/container.xml', containerXml)
this.zip.file('OEBPS/content.opf', Buffer.from(await template.createOpf(this), 'utf8')) 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) this.filename = FimFic2Epub.getFilename(this.storyInfo)
} }
setCoverImage (buffer) { setCoverImage (buffer) {
buffer = isNode ? buffer : new Uint8Array(buffer) buffer = isNode ? buffer : Buffer.from(new Uint8Array(buffer))
let info = fileType(buffer) let info = fileType(buffer)
if (!info || !info.mime.startsWith('image/')) { if (!info || !info.mime.startsWith('image/')) {
throw new Error('Invalid image') throw new Error('Invalid image')
@ -869,4 +869,4 @@ class FimFic2Epub extends EventEmitter {
} }
} }
module.exports = FimFic2Epub export default FimFic2Epub

View file

@ -39,7 +39,7 @@ if (outputStdout) {
require('mithril/test-utils/browserMock')(global) require('mithril/test-utils/browserMock')(global)
const htmlToText = require('./utils').htmlToText const htmlToText = require('./utils').htmlToText
const FimFic2Epub = require('./FimFic2Epub') const FimFic2Epub = require('./FimFic2Epub').default
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')

View file

@ -167,8 +167,12 @@ let dialog = {
} }
this.setCoverFile = (e) => { this.setCoverFile = (e) => {
this.coverUrl('') let el = e.dom || e.target
this.coverFile(e.target.files ? e.target.files[0] : null) if (el.target) {
this.coverUrl('')
}
this.coverFile(el.files ? el.files[0] : null)
console.log('files:', el.files)
} }
this.setSubjects = function () { 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', '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('tr', m('td.label', 'Custom cover image'),
m('td', 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')) 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()) { } else if (model.coverFile()) {
chain = chain chain = chain
.then(() => blobToArrayBuffer(model.coverFile())) .then(() => blobToArrayBuffer(model.coverFile()))
.then(ffc.setCoverImage.bind(ffc)) .then((buf) => {
ffc.setCoverImage(buf)
}).catch((err) => console.error(err))
} }
ffc.setTitle(model.title()) ffc.setTitle(model.title())

View file

@ -1,13 +1,18 @@
const styleCss = require('./style/style') import styleCss from './style/style'
const coverstyleCss = require('./style/coverstyle') import coverstyleCss from './style/coverstyle'
const titlestyleCss = require('./style/titlestyle') import titlestyleCss from './style/titlestyle'
const navstyleCss = require('./style/navstyle') import navstyleCss from './style/navstyle'
const iconsCss = require('./style/icons') 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 = { const paragraphsCss = {
spaced: require('./style/paragraphs-spaced'), spaced: paragraphsSpaced,
indented: require('./style/paragraphs-indented'), indented: paragraphsIndented,
indentedall: require('./style/paragraphs-indentedall') indentedall: paragraphsIndentAll
} }
paragraphsCss.both = paragraphsCss.indented + '\n' + paragraphsCss.spaced paragraphsCss.both = paragraphsCss.indented + '\n' + paragraphsCss.spaced

View file

@ -19,16 +19,17 @@ const bundleExtensionConfig = {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/, exclude: /node_modules/,
query: { use: {
presets: [['env', { loader: 'babel-loader',
targets: { options: {
browsers: ['chrome 50', 'firefox 47'] presets: [['@babel/env', {
}, targets: {
modules: false, browsers: ['chrome 50', 'firefox 47']
useBuiltIns: true },
}]] modules: false
}]]
}
} }
}, },
{ {
@ -85,15 +86,17 @@ const bundleNpmModuleConfig = {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/, exclude: /node_modules/,
query: { use: {
sourceMaps: !inProduction, loader: 'babel-loader',
presets: [['env', { options: {
targets: { sourceMaps: !inProduction,
node: '8.0.0' presets: [['@babel/env', {
} targets: {
}]] node: '8.0.0'
}
}]]
}
} }
}, },
{ {
@ -108,7 +111,7 @@ const bundleNpmModuleConfig = {
}, },
resolve: { resolve: {
extensions: ['.js', '.json', '.styl'], extensions: ['.js', '.json', '.styl', '.node'],
modules: [ modules: [
path.resolve('./src'), path.resolve('./src'),
'node_modules' 'node_modules'
@ -147,22 +150,24 @@ const bundleNpmBinaryConfig = {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/, exclude: /node_modules/,
query: { use: {
sourceMaps: !inProduction, loader: 'babel-loader',
presets: [['env', { options: {
targets: { sourceMaps: !inProduction,
node: '8.0.0' presets: [['@babel/env', {
} targets: {
}]] node: '8.0.0'
}
}]]
}
} }
} }
] ]
}, },
resolve: { resolve: {
extensions: ['.js', '.json'], extensions: ['.js', '.json', '.node'],
modules: [ modules: [
path.resolve('./src'), path.resolve('./src'),
'node_modules' 'node_modules'
@ -204,15 +209,17 @@ const bundleStaticNpmModuleConfig = {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/, exclude: /node_modules/,
query: { use: {
sourceMaps: !inProduction, loader: 'babel-loader',
presets: [['env', { options: {
targets: { sourceMaps: !inProduction,
node: 'current' presets: [['@babel/env', {
} targets: {
}]] node: 'current'
}
}]]
}
} }
}, },
{ {
@ -227,7 +234,7 @@ const bundleStaticNpmModuleConfig = {
}, },
resolve: { resolve: {
extensions: ['.js', '.json', '.styl'], extensions: ['.js', '.json', '.styl', '.node'],
modules: [ modules: [
path.resolve('./bin'), path.resolve('./bin'),
'node_modules' 'node_modules'