-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstart-dev.js
More file actions
79 lines (64 loc) · 1.48 KB
/
Copy pathstart-dev.js
File metadata and controls
79 lines (64 loc) · 1.48 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
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
const { spawn } = require('node:child_process');
const isProduction = (process.env.NODE_ENV || '').toLowerCase() === 'production';
const childProcesses = [];
let shuttingDown = false;
function spawnNodeProcess(args) {
const child = spawn(process.execPath, args, {
stdio: 'inherit',
env: process.env
});
childProcesses.push(child);
child.on('exit', (code, signal) => {
if (shuttingDown) {
return;
}
shuttingDown = true;
stopAllChildren(child);
if (typeof code === 'number') {
process.exit(code);
return;
}
process.exit(signal ? 1 : 0);
});
child.on('error', (error) => {
if (shuttingDown) {
return;
}
shuttingDown = true;
console.error(error);
stopAllChildren(child);
process.exit(1);
});
}
function stopAllChildren(excludeChild) {
for (const child of childProcesses) {
if (child === excludeChild || child.killed) {
continue;
}
child.kill('SIGTERM');
}
}
function shutdown() {
if (shuttingDown) {
return;
}
shuttingDown = true;
stopAllChildren();
process.exit(0);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
if (isProduction) {
spawnNodeProcess(['app.js']);
} else {
spawnNodeProcess(['app.js']);
spawnNodeProcess([
'--watch-preserve-output',
'--watch-path=map/journeys',
'--watch-path=map/templates',
'--watch-path=map/assets',
'--watch-path=map/build.js',
'--watch-path=map/router.js',
'map/build.js'
]);
}