-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
105 lines (83 loc) · 2.49 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
var gulp = require('gulp');
var babel = require('gulp-babel');
var sass = require('gulp-sass');
var gulpSequence = require('gulp-sequence');
var concat = require('gulp-concat');
var util = require('gulp-util');
var filter = require('gulp-filter');
var env = require('gulp-env');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');
var child = require('child_process');
var path = {
SRV_SRC: ['src/server/**/*', '!*~'],
CNF_SRC: ['src/config/**/*', '!*~'],
OUT_DIR: 'dist/'
};
var server = null;
gulp.task('default', gulpSequence(['server:build', 'config:copy', 'client:copy', 'server:spawn'], 'watch'));
gulp.task('watch', function() {
gulp.watch(path.SRV_SRC, ['server:rebuild']);
});
gulp.task('client:copy', function() {
gulp.src('./src/client/index.html')
.pipe(gulp.dest(path.OUT_DIR + 'public'));
gulp.src('./src/client/robots.txt')
.pipe(gulp.dest(path.OUT_DIR + 'public'));
gulp.src('./src/client/favicon.ico')
.pipe(gulp.dest(path.OUT_DIR + 'public'));
gulp.src('./src/client/assets/**/*')
.pipe(gulp.dest(path.OUT_DIR + 'public/assets'));
});
gulp.task('config:copy', function() {
gulp.src(path.CNF_SRC)
.pipe(gulp.dest(path.OUT_DIR + '/config'));
});
gulp.task('server:rebuild', function(next) {
gulpSequence('server:build', 'server:spawn')(next);
});
gulp.task('client:build', function(callback) {
webpackConfig.mode = 'production';
webpack(webpackConfig, function(err, stats) {
if (err) throw new util.PluginError("client:build", err);
util.log("[client:build]", stats.toString({ colors: true }));
callback();
});
});
gulp.task('server:build', function() {
gulp.src(path.SRV_SRC)
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest(path.OUT_DIR));
});
gulp.task('server:env-release', function() {
env({
vars: {
NODE_ENV: "production"
}
});
});
gulp.task('server:release', ['server:env-release', 'server:build']);
gulp.task('server:spawn', function() {
if (server) {
server.kill();
}
server = child.spawn('node', ['dist/server.js']);
server.on('close', function(code) {
if (code === 8) {
util.log('Error detected, waiting for changes ...');
}
});
server.stdout.on('data', function(data) {
util.log(util.colors.green(String(data).trim()));
});
server.stderr.on('data', function(data) {
util.log(util.colors.red(String(data).trim()));
});
});
process.on('exit', function() {
if (server) {
server.kill();
}
});