nifty-wallet/gulpfile.js

157 lines
4.6 KiB
JavaScript
Raw Normal View History

2016-03-02 23:06:43 -08:00
var watchify = require('watchify')
var browserify = require('browserify')
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var gutil = require('gulp-util')
var watch = require('gulp-watch')
var sourcemaps = require('gulp-sourcemaps')
var assign = require('lodash.assign')
var livereload = require('gulp-livereload')
var del = require('del')
2016-06-21 12:07:13 -07:00
var eslint = require('gulp-eslint')
2016-03-02 23:06:43 -08:00
// browser reload
gulp.task('dev:reload', function() {
livereload.listen({
port: 35729,
2016-03-11 15:21:43 -08:00
// basePath: './dist/'
2016-03-02 23:06:43 -08:00
})
})
// copy static
gulp.task('copy:locales', copyTask({
source: './app/_locales/',
2016-03-11 15:21:43 -08:00
destination: './dist/_locales',
2016-03-02 23:06:43 -08:00
}))
gulp.task('copy:images', copyTask({
source: './app/images/',
2016-03-11 15:21:43 -08:00
destination: './dist/images',
2016-03-02 23:06:43 -08:00
}))
gulp.task('copy:fonts', copyTask({
source: './app/fonts/',
destination: './dist/fonts',
}))
2016-03-02 23:06:43 -08:00
gulp.task('copy:reload', copyTask({
source: './app/scripts/',
2016-03-11 15:21:43 -08:00
destination: './dist/scripts',
2016-03-02 23:06:43 -08:00
pattern: '/chromereload.js',
}))
gulp.task('copy:root', copyTask({
source: './app/',
2016-03-11 15:21:43 -08:00
destination: './dist',
2016-03-02 23:06:43 -08:00
pattern: '/*',
}))
gulp.task('copy', gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'))
2016-03-02 23:06:43 -08:00
gulp.task('copy:watch', function(){
2016-06-14 12:43:55 -07:00
gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy'))
2016-03-02 23:06:43 -08:00
})
2016-06-21 12:07:13 -07:00
// lint js
gulp.task('lint', function () {
// Ignoring node_modules, dist, and docs folders:
return gulp.src(['app/**/*.js', 'ui/**/*.js', '!node_modules/**', '!dist/**', '!docs/**'])
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError())
});
/*
gulp.task('default', ['lint'], function () {
// This will only run if the lint task is successful...
});
*/
2016-03-02 23:06:43 -08:00
// build js
gulp.task('dev:js:inpage', bundleTask({ watch: true, filename: 'inpage.js' }))
gulp.task('dev:js:contentscript', bundleTask({ watch: true, filename: 'contentscript.js' }))
gulp.task('dev:js:background', bundleTask({ watch: true, filename: 'background.js' }))
gulp.task('dev:js:popup', bundleTask({ watch: true, filename: 'popup.js' }))
gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup'))
gulp.task('build:js:inpage', bundleTask({ watch: false, filename: 'inpage.js' }))
gulp.task('build:js:contentscript', bundleTask({ watch: false, filename: 'contentscript.js' }))
gulp.task('build:js:background', bundleTask({ watch: false, filename: 'background.js' }))
gulp.task('build:js:popup', bundleTask({ watch: false, filename: 'popup.js' }))
gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup'))
// clean dist
gulp.task('clean', function clean() {
2016-03-11 15:21:43 -08:00
return del(['./dist'])
2016-03-02 23:06:43 -08:00
})
// high level tasks
2016-06-21 12:07:13 -07:00
gulp.task('dev', gulp.series('dev:js', 'copy', gulp.parallel('copy:watch', 'dev:reload', 'lint')))
gulp.task('build', gulp.series('clean', gulp.parallel('build:js', 'copy', 'lint')))
2016-03-02 23:06:43 -08:00
// task generators
function copyTask(opts){
var source = opts.source
var destination = opts.destination
var pattern = opts.pattern || '/**/*'
return performCopy
function performCopy(){
return (
gulp.src(source + pattern, { base: source })
.pipe(gulp.dest(destination))
.pipe(livereload())
)
}
}
function bundleTask(opts) {
var browserifyOpts = assign({}, watchify.args, {
entries: ['./app/scripts/'+opts.filename],
debug: true,
2016-04-20 13:22:41 -07:00
plugin: 'browserify-derequire',
2016-03-02 23:06:43 -08:00
})
var bundler = browserify(browserifyOpts)
bundler.transform('brfs')
2016-03-02 23:06:43 -08:00
if (opts.watch) {
bundler = watchify(bundler)
bundler.on('update', performBundle) // on any dep update, runs the bundler
}
bundler.on('log', gutil.log) // output build logs to terminal
return performBundle
function performBundle(){
return (
bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source(opts.filename))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
2016-03-02 23:06:43 -08:00
.pipe(sourcemaps.write('./')) // writes .map file
2016-03-11 15:21:43 -08:00
.pipe(gulp.dest('./dist/scripts'))
2016-03-02 23:06:43 -08:00
.pipe(livereload())
)
}
}