-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuilder.js
More file actions
39 lines (33 loc) · 1.01 KB
/
Copy pathbuilder.js
File metadata and controls
39 lines (33 loc) · 1.01 KB
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
var _ = require('./lib/underscore'),
config = require('./config'),
deps = require('./deps'),
fs = require('fs'),
child_process = require('child_process');
if (config.DAEMON)
throw "Can't run dev server in daemon mode.";
var server;
var start_server = _.debounce(function () {
if (server)
server.kill('SIGTERM');
server = child_process.spawn('node', ['server/server.js']);
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
}, 500);
var reload_state = _.debounce(function () {
if (server)
server.kill('SIGHUP');
}, 500);
deps.SERVER_DEPS.forEach(monitor.bind(null, start_server));
deps.SERVER_STATE.forEach(monitor.bind(null, reload_state));
deps.CLIENT_DEPS.forEach(monitor.bind(null, reload_state));
deps.MOD_CLIENT_DEPS.forEach(monitor.bind(null, reload_state));
function monitor(func, dep) {
var mtime = new Date;
fs.watchFile(dep, {interval: 500, persistent: true}, function (event) {
if (event.mtime > mtime) {
func();
mtime = event.mtime;
}
});
}
start_server();