-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (57 loc) · 2.03 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-env node */
'use strict';
var bg = require('gulp-bg');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var harmonize = require('harmonize');
var jest = require('jest-cli');
var makeWebpackConfig = require('./webpack/makeconfig');
var runSequence = require('run-sequence');
var webpackBuild = require('./webpack/build');
var webpackDevServer = require('./webpack/devserver');
var yargs = require('yargs');
// Enables node's --harmony flag programmatically for jest.
harmonize();
var args = yargs
.alias('p', 'production')
.argv;
gulp.task('env', function() {
process.env.NODE_ENV = args.production ? 'production' : 'development';
});
gulp.task('build-webpack-production', webpackBuild(makeWebpackConfig(false)));
gulp.task('build-webpack-dev', webpackDevServer(makeWebpackConfig(true)));
gulp.task('build-webpack', [args.production ? 'build-webpack-production' : 'build-webpack-dev']);
gulp.task('build', ['build-webpack']);
gulp.task('eslint', function() {
return gulp.src([
'gulpfile.js',
'src/**/*.js',
'webpack/*.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('jest', function(done) {
var rootDir = './src';
jest.runCLI({config: {
'rootDir': rootDir,
'scriptPreprocessor': '../node_modules/babel-jest',
'testFileExtensions': ['es6', 'js'],
'moduleFileExtensions': ['js', 'json', 'es6']
}}, rootDir, function(success) {
/* eslint no-process-exit:0 */
done(success ? null : 'jest failed');
process.on('exit', function() {
process.exit(success ? 0 : 1);
});
});
});
gulp.task('test', function(done) {
// Run test tasks serially, because it doesn't make sense to build when tests
// are not passing, and it doesn't make sense to run tests, if lint has failed.
// Gulp deps aren't helpful, because we want to run tasks without deps as well.
runSequence('eslint', 'jest', 'build-webpack-production', done);
});
gulp.task('server', ['env', 'build'], bg('node', 'src/server'));
gulp.task('default', ['server']);