UNPKG

1.21 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/**
4 * this code credit: TJ et al (https://github.com/mochajs/mocha framework)
5 * This tiny wrapper file checks for known node flags and appends them
6 * when found, before invoking the "real" executable.
7 */
8
9var spawn = require('child_process').spawn
10 , args = [ __dirname + '/_pub' ];
11
12
13process.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
36var proc = spawn(process.argv[0], args, { stdio: 'inherit' });
37proc.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// terminate children.
48process.on('SIGINT', function() {
49 proc.kill('SIGINT'); // calls runner.abort()
50 proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
51 process.kill(process.pid, 'SIGINT');
52});