dispatch/client/gulpfile.js

122 lines
3.2 KiB
JavaScript
Raw Normal View History

2015-04-29 22:45:02 +00:00
var exec = require('child_process').exec;
2015-01-17 01:37:21 +00:00
var gulp = require('gulp');
var gulpif = require('gulp-if');
var minifyHTML = require('gulp-minify-html');
var minifyCSS = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
2015-02-05 00:37:34 +00:00
var gzip = require('gulp-gzip');
2015-05-12 21:50:55 +00:00
var concat = require('gulp-concat');
2015-01-17 01:37:21 +00:00
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
2015-02-21 06:23:25 +00:00
var babelify = require('babelify');
2015-01-17 01:37:21 +00:00
var strictify = require('strictify');
var watchify = require('watchify');
var argv = require('yargs')
.alias('p', 'production')
.argv;
if (argv.production) {
process.env['NODE_ENV'] = 'production';
}
gulp.task('html', function() {
return gulp.src('src/*.html')
2015-01-17 01:37:21 +00:00
.pipe(minifyHTML())
.pipe(gulp.dest('dist'));
2015-01-17 01:37:21 +00:00
});
gulp.task('css', function() {
return gulp.src(['src/css/fontello.css', 'src/css/style.css'])
2015-05-12 21:50:55 +00:00
.pipe(concat('bundle.css'))
2015-01-17 01:37:21 +00:00
.pipe(autoprefixer())
.pipe(minifyCSS())
2015-05-12 21:50:55 +00:00
.pipe(gulp.dest('dist'));
2015-01-17 01:37:21 +00:00
});
gulp.task('js', function() {
return js(false);
});
function js(watch) {
var bundler, rebundle;
bundler = browserify('./src/js/app.js', {
debug: !argv.production,
cache: {},
packageCache: {},
fullPaths: watch
});
if (watch) {
bundler = watchify(bundler);
}
bundler
2015-02-21 06:23:25 +00:00
.transform(babelify)
2015-01-17 01:37:21 +00:00
.transform(strictify);
rebundle = function() {
var stream = bundler.bundle();
stream.on('error', console.log);
return stream
.pipe(source('bundle.js'))
.pipe(gulpif(argv.production, streamify(uglify())))
.pipe(gulp.dest('dist'));
2015-01-17 01:37:21 +00:00
};
bundler.on('time', function(time) {
console.log('JS bundle: ' + time + ' ms');
});
bundler.on('update', rebundle);
return rebundle();
}
2015-02-16 20:53:01 +00:00
gulp.task('fonts', function() {
return gulp.src('src/font/*')
.pipe(gulp.dest('dist/font'));
2015-02-16 20:53:01 +00:00
});
gulp.task('config', function() {
return gulp.src('../config.default.toml')
.pipe(gulp.dest('dist/gz'));
});
2015-02-16 20:53:01 +00:00
gulp.task('gzip', ['html', 'css', 'js', 'fonts'], function() {
return gulp.src(['dist/**/!(*.gz)', '!dist/{gz,gz/**}'])
2015-02-05 00:37:34 +00:00
.pipe(gzip())
.pipe(gulp.dest('dist/gz'));
2015-02-05 00:37:34 +00:00
});
2015-04-29 22:45:02 +00:00
function bindata(cb) {
if (argv.production) {
exec('go-bindata -nomemcopy -nocompress -pkg assets -o ../assets/bindata.go -prefix "dist/gz" dist/gz/...', cb);
2015-04-29 22:45:02 +00:00
} else {
exec('go-bindata -debug -pkg assets -o ../assets/bindata.go -prefix "dist/gz" dist/gz/...', cb);
2015-04-29 22:45:02 +00:00
}
}
gulp.task('bindata', ['gzip', 'config'], function(cb) {
2015-04-29 22:45:02 +00:00
bindata(cb);
});
2015-02-05 00:37:34 +00:00
gulp.task('gzip:watch', function() {
return gulp.src('dist/**/*.{html,css,js}')
2015-02-05 00:37:34 +00:00
.pipe(gzip())
.pipe(gulp.dest('dist/gz'));
2015-02-05 00:37:34 +00:00
});
2015-04-29 22:45:02 +00:00
gulp.task('bindata:watch', ['gzip:watch'], function(cb) {
bindata(cb);
});
2015-01-17 01:37:21 +00:00
gulp.task('watch', ['default'], function() {
2015-04-29 22:45:02 +00:00
gulp.watch('dist/**/*.{html,css,js}', ['gzip:watch', 'bindata:watch'])
gulp.watch('src/*.html', ['html']);
gulp.watch('src/css/*.css', ['css']);
2015-01-17 01:37:21 +00:00
return js(true);
});
gulp.task('default', ['html', 'css', 'js', 'fonts', 'config', 'gzip', 'bindata']);