fimfic2epub/gulpfile.babel.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-06-21 09:04:08 +12:00
'use strict'
// gulp and utilities
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'
2016-06-21 19:14:57 +12:00
import filter from 'gulp-filter'
2016-06-21 09:04:08 +12:00
// script
2016-06-21 18:39:26 +12:00
import standard from 'gulp-standard'
2016-06-21 09:04:08 +12:00
import webpack from 'webpack'
import webpackConfig from './webpack.config.babel.js'
const sequence = Sequence.use(gulp)
let inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
let watchOpts = {
2016-06-21 18:39:26 +12:00
readDelay: 500,
verbose: true
2016-06-21 09:04:08 +12:00
}
if (inProduction) {
2016-06-21 18:39:26 +12:00
webpackConfig.plugins.push(new webpack.optimize.DedupePlugin())
webpackConfig.plugins.push(new webpack.optimize.OccurenceOrderPlugin(false))
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true
},
comments: false,
mangle: {
screw_ie8: true
},
screw_ie8: true,
sourceMap: false
}))
2016-06-21 09:04:08 +12:00
}
let wpCompiler = webpack(Object.assign({}, webpackConfig, {
2016-06-21 18:39:26 +12:00
cache: {},
devtool: inProduction ? null : 'inline-source-map',
debug: !inProduction
2016-06-21 09:04:08 +12:00
}))
2016-06-21 18:39:26 +12:00
function webpackTask (callback) {
// run webpack
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,
chunkModules: false
}))
callback()
})
2016-06-21 09:04:08 +12:00
}
2016-06-21 18:39:26 +12:00
let lintPipe = lazypipe()
2016-06-21 19:55:43 +12:00
.pipe(filter, ['**/*', '!extension/fimfic2epub.js'])
2016-06-21 18:39:26 +12:00
.pipe(standard)
2016-06-21 19:14:57 +12:00
.pipe(standard.reporter, 'default', { breakOnError: false })
2016-06-21 09:04:08 +12:00
2016-06-21 18:39:26 +12:00
// Cleanup task
gulp.task('clean', () => del('extension/fimfic2epub.js'))
2016-06-21 09:04:08 +12:00
// Main tasks
gulp.task('webpack', webpackTask)
2016-06-21 21:32:49 +12:00
gulp.task('watch:webpack', () => {
return watch(['src/**/*.js', 'src/**/*.styl'], watchOpts, function () {
return sequence('webpack')
2016-06-21 18:39:26 +12:00
})
2016-06-21 09:04:08 +12:00
})
gulp.task('lint', () => {
2016-06-21 19:14:57 +12:00
return gulp.src(['gulpfile.babel.js', 'webpack.config.babel.js', 'src/**/*.js', 'extension/**/*.js']).pipe(lintPipe())
2016-06-21 09:04:08 +12:00
})
gulp.task('watch:lint', () => {
2016-06-21 18:39:26 +12:00
return watch(['src/**/*.js'], watchOpts, function (file) {
gulp.src(file.path).pipe(lintPipe())
})
2016-06-21 09:04:08 +12:00
})
// Default task
gulp.task('default', (done) => {
2016-06-21 21:32:49 +12:00
sequence('clean', ['webpack', 'lint'], done)
2016-06-21 09:04:08 +12:00
})
// Watch task
gulp.task('watch', (done) => {
2016-06-21 21:32:49 +12:00
sequence('default', ['watch:lint', 'watch:webpack'], done)
2016-06-21 18:39:26 +12:00
})