-
Notifications
You must be signed in to change notification settings - Fork 16
/
run.js
executable file
·81 lines (59 loc) · 1.43 KB
/
run.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
#!/usr/bin/env node
var program = require('commander'),
child_process = require('child_process'),
path = require('path'),
chokidar = require('chokidar'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server')
util = require('util'),
_ = require('underscore');
function run(){
var server = null;
function start() {
server = child_process.spawn('/usr/bin/env', ['node', 'src/server/node'], {
cwd: __dirname,
stdio: ['ignore', 1, 2]
});
// Restart server on exit
server.on('exit', function(code, signal) {
console.log('Server exited.');
start();
});
}
start();
buildServer();
var watcher = chokidar.watch(path.resolve(__dirname, '../src/server/node/**/*.js'), {
//ignored: /[\/\\]\./,
persistent: true
});
watcher.on('change', (path, stats) => {
console.log('CHANGE')
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
if(server){
console.log('Stopping server')
server.kill('SIGINT')
return;
}
});
process.on('exit', function() {
if(server != null){
console.log('Killing server')
server.kill('SIGINT');
}
})
}
function buildServer() {
var config = require("./webpack.config.js");
var compiler = webpack(config);
var server = new WebpackDevServer(compiler, {
// webpack-dev-middleware settings
publicPath: '/assets',
stats: {
chunks: false,
children: false,
colors: true
}
});
server.listen(4200);
}
run();