-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
149 lines (135 loc) · 4.66 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const gulp = require('gulp'),
eslint = require('gulp-eslint'),
gutil = require('gulp-util'),
Promise = require('bluebird'),
sourcemaps = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
env = require('gulp-env'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
_ = require('lodash'),
jsdoc = require('gulp-jsdoc3');
var jsFiles = ['*.js', 'src/**/*.js', 'src/**/*.jsx', '!./**/node_modules/**/*', '!./src/parser/compiled/**/*'];
var assets = ['assets/**/*'];
var parserSrcCode = ['src/parser/**.js'];
gulp.task('lint', function () {
return gulp.src(jsFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('doc', function (cb) {
gulp.src(['README.md', './src/**/*.js'], {read: false})
.pipe(jsdoc({}, cb));
});
gulp.task('lint-watch', function () {
var runSequence = require('run-sequence');
runSequence('lint', function () {
gulp.watch(jsFiles, ['lint']);
});
});
gulp.task('build-parser', function () {
return gulp.src(parserSrcCode)
.pipe(sourcemaps.init())
.pipe(babel())
.on('error', function (error) {
gutil.log(error.toString());
this.emit('end');
})
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('src/parser/compiled'));
});
gulp.task('watch-build-parser', function (cb) { // eslint-disable-line no-unused-vars
var runSequence = require('run-sequence');
runSequence('build-parser', function () {
gulp.watch(parserSrcCode, ['build-parser']);
});
});
gulp.task('copy', function () {
return gulp.src(assets)
.pipe(gulp.dest('dist/'));
});
gulp.task('webpack-dev', function (callback) {
env.set({
vars: {
'DEBUG': '', // Debugger logging if we need it
'NODE_ENV': 'development'
}
});
const config = require('./webpack.config').dev;
webpack(config).run(function (err, stats) {
if (err) throw new gutil.PluginError('webpack-dev', err);
gutil.log('[webpack-dev]', stats.toString({colors: true, timings: true, reasons: true}));
callback();
});
});
gulp.task('webpack', function (callback) {
env.set({
vars: {
'NODE_ENV': 'production'
}
});
const config = require('./webpack.config').prod;
webpack(config).run(function (err, stats) {
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({colors: true, timings: true, reasons: true}));
callback();
});
});
gulp.task('webpack-dev-server', function (callback) { //eslint-disable-line no-unused-vars
env.set({
vars: {
'DEBUG': '', // Debugger logging if we need it
'NODE_ENV': 'development'
}
});
const config = require('./webpack.config').dev;
const port = _.last(config.entry[0].split(':'));
const compiler = webpack(config);
new WebpackDevServer(compiler, {
// Needs to be here and in webpack
contentBase: config.devServer.contentBase,
hot: true,
stats: {colors: true, timings: true, reasons: true}
// server and middleware options
}).listen(port, '0.0.0.0', function (error) {
if (error) {
throw new gutil.PluginError('webpack-dev-server', error);
}
gutil.log('[webpack-dev-server]', 'http://localhost:' + port + '/webpack-dev-server/');
});
// Ignore callback
});
function SpawnTask(cmd, args) { //eslint-disable-line no-unused-vars
// You could get an error then a close or just an error.
// So we use promises and ignore the second
return new Promise(function (resolve, reject) {
args = args || [];
gutil.log(cmd + ' ' + args.join(' '));
const child = require('child_process').spawn(cmd, args, {cwd: process.cwd()});
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function (data) {
gutil.log(data);
});
child.stderr.on('data', function (data) {
gutil.log(gutil.colors.red(data));
gutil.beep();
});
child.on('close', function (code) {
if (code === 0) {
gutil.log('Finished with exit code 0');
resolve();
} else {
gutil.log(gutil.colors.red('Closed with error code: ' + code));
gutil.beep();
reject(code);
}
});
child.on('error', function (error) {
gutil.log(gutil.colors.red(error));
gutil.beep();
reject(error);
});
});
}