1 // Copyright 2015-present Greg Hurrell. All rights reserved.
2 // Licensed under the terms of the MIT license.
4 import WebpackDevServer from 'webpack-dev-server';
5 import config from './webpack.config.js';
6 import eslint from 'gulp-eslint';
7 import flow from 'gulp-flowtype';
8 import gulp from 'gulp';
9 import gutil from 'gulp-util';
10 import mocha from 'gulp-spawn-mocha';
11 import productionConfig from './webpack.production.config.js';
12 import webpack from 'webpack';
17 * Ring the terminal bell.
20 process.stderr.write('\x07');
24 * Wrap a stream in an error-handler (until Gulp 4, needed to prevent "watch"
25 * task from dying on error).
27 function wrap(stream) {
28 stream.on('error', error => {
29 gutil.log(gutil.colors.red(error.message));
30 gutil.log(error.stack);
32 gutil.log(gutil.colors.yellow('[aborting]'));
35 gutil.log(gutil.colors.yellow('[exiting]'));
43 gulp.task('default', ['webpack-dev-server']);
45 gulp.task('build', ['webpack:build']);
47 gulp.task('flow', ['typecheck']);
49 gulp.task('js', ['build', 'lint', 'test', 'typecheck']);
51 gulp.task('lint', () => (
52 gulp.src('src/**/*.js')
54 .pipe(eslint.format())
57 gulp.task('typecheck', () => {
58 return gulp.src('src/**/*.js', {read: false})
61 // TODO: enable this once Flow groks ES2015/ES2016 features.
62 return gulp.src('src/**/*.js')
66 gulp.task('test', () => (
69 'src/**/__mocks__/*.js',
70 'src/**/__tests__/*-test.js',
75 opts: 'mocha/mocha.opts',
76 reporter: watching ? 'mocha/watch-reporter' : 'list',
80 gulp.task('watch', () => {
82 gulp.watch('src/**/*.js', ['js']);
85 gulp.task('webpack:build', callback => {
86 webpack(productionConfig, (err, stats) => {
89 throw new gutil.PluginError('webpack:build', err);
91 if (stats.compilation.errors) {
95 gutil.log('[webpack:build]', stats.toString({
103 gulp.task('webpack-dev-server', callback => {
109 new WebpackDevServer(webpack(myConfig), {
110 publicPath: config.output.publicPath,
112 historyApiFallback: true,
116 }).listen(3000, 'localhost', err => {
119 throw new gutil.PluginError('webpack-dev-server', err);
121 gutil.log('[webpack-dev-server]', 'http://localhost:3000');