-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
52 lines (44 loc) · 1.29 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
var gulp = require('gulp');
var webpack = require('gulp-webpack');
var del = require('del');
var webpackConfig = require('./webpack.config');
var spawn = require('child_process').spawn;
var CWD = process.cwd();
var isBuild = true;
gulp.task('clean', function(cb) {
isBuild ? del('./source/js', cb) : cb();
});
gulp.task('webpack', ['clean'], function() {
return gulp.src('./')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('./source/js'));
});
gulp.task('build', ['clean', 'webpack']);
gulp.task('default', ['build']);
gulp.task('watch', ['build'],function() {
isBuild = false;
gulp.watch(['./src/**/*.jsx', './src/**/*.less'], ['build']);
});
function run(command, args) {
return new Promise(function(resolve, reject) {
var task = spawn(command, args, {
cwd: CWD
});
task.on('close', function(code) {
if (code !== 0) reject(new Error(command + ' process exited with code ' + code));
else resolve();
});
task.stdout.pipe(process.stdout);
task.stderr.pipe(process.stderr);
});
}
gulp.task('dev', function() {
run('node_modules/.bin/gulp').then(function() {
return Promise.all([
run('node_modules/.bin/ka', ['-p', '9999']),
run('node_modules/.bin/gulp', ['watch'])
]);
}).catch(function(e) {
console.error(e.message);
});
});