1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var spawn = require('child_process').spawn
|
10 | , args = [ __dirname + '/_pub' ];
|
11 |
|
12 |
|
13 | process.argv.slice(2).forEach(function(arg){
|
14 | var flag = arg.split('=')[0];
|
15 |
|
16 | switch (flag) {
|
17 | case '-?':
|
18 | case '-H':
|
19 | args.push('-h');
|
20 | break;
|
21 | case '-D':
|
22 | args.unshift('--inspect');
|
23 | args.push('--dbg');
|
24 | break;
|
25 | case '-B':
|
26 | args.unshift('--inspect');
|
27 | args.unshift('--debug-brk');
|
28 | args.push('--dbg');
|
29 | break;
|
30 | default:
|
31 | args.push(arg);
|
32 | break;
|
33 | }
|
34 | });
|
35 |
|
36 | var proc = spawn(process.argv[0], args, { stdio: 'inherit' });
|
37 | proc.on('exit', function(code, signal) {
|
38 | process.on('exit', function(){
|
39 | if (signal) {
|
40 | process.kill(process.pid, signal);
|
41 | } else {
|
42 | process.exit(code);
|
43 | }
|
44 | });
|
45 | });
|
46 |
|
47 |
|
48 | process.on('SIGINT', function() {
|
49 | proc.kill('SIGINT');
|
50 | proc.kill('SIGTERM');
|
51 | process.kill(process.pid, 'SIGINT');
|
52 | });
|