/
gulpfile.babel.js
70 lines (60 loc) · 1.96 KB
/
gulpfile.babel.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
69
70
import bg from 'gulp-bg';
import eslint from 'gulp-eslint';
import gulp from 'gulp';
import makeWebpackConfig from './webpack/makeconfig';
import path from 'path';
import runSequence from 'run-sequence';
import webpackBuild from './webpack/build';
import webpackDevServer from './webpack/devserver';
import yargs from 'yargs';
import {server as karmaServer} from 'karma';
const args = yargs
.alias('p', 'production')
.argv;
const runKarma = ({singleRun}, done) => {
karmaServer.start({
configFile: path.join(__dirname, 'karma.conf.js'), // eslint-disable-line no-undef
singleRun: singleRun
}, done);
};
gulp.task('env', () => {
const env = args.production ? 'production' : 'development';
process.env.NODE_ENV = env; // eslint-disable-line no-undef
});
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', () => {
return gulp.src([
'gulpfile.babel.js',
'src/**/*.js',
'webpack/*.js',
'!**/__tests__/*.*'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('karma-ci', (done) => {
runKarma({singleRun: true}, done);
});
gulp.task('karma-dev', (done) => {
runKarma({singleRun: false}, done);
});
gulp.task('test', (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', 'karma-ci', 'build-webpack-production', done);
});
gulp.task('server', ['env', 'build'], bg('node', 'src/server'));
gulp.task('default', (done) => {
if (args.production)
runSequence('server', done);
else
runSequence('server', 'karma-dev', done);
});