-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
104 lines (95 loc) · 2.27 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
var args = resolveNativeNodeArgumentsIfAny();
if (args) {
runNewNode(args);
} else {
let run = require('./lib/cli');
run().catch(error => {
console.error('AppBundler Failed', error);
});
}
function runNewNode (args) {
var spawn = require('child_process').spawn;
var path = require('path');
var proc = spawn(process.execPath, args, { stdio: 'inherit' });
proc.on('exit', function (code, signal) {
process.on('exit', function () {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
});
});
// terminate children.
process.on('SIGINT', function () {
proc.kill('SIGINT'); // calls runner.abort()
proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
});
}
function resolveNativeNodeArgumentsIfAny () {
var path = require('path');
var args = [path.join(__dirname, 'index.js')];
var isDebug = false;
var count = 0;
process.argv.slice(2).forEach(function (arg) {
var flag = arg.split('=')[0];
switch (flag) {
case '-d':
args.unshift('--debug');
break;
case 'debug':
args.unshift('--inspect');
isDebug = true;
break;
case '--debug':
case '--debug-brk':
case '--inspect':
case '--inspect-brk':
args.unshift(arg);
break;
case '-gc':
case '--expose-gc':
args.unshift('--expose-gc');
break;
case '--gc-global':
case '--es_staging':
case '--no-deprecation':
case '--no-warnings':
case '--prof':
case '--log-timer-events':
case '--throw-deprecation':
case '--trace-deprecation':
case '--trace-warnings':
case '--use_strict':
case '--allow-natives-syntax':
case '--perf-basic-prof':
case '--napi-modules':
args.unshift(arg);
break;
default:
if (arg.indexOf('--harmony') === 0) {
args.unshift(arg);
} else if (arg.indexOf('--trace') === 0) {
args.unshift(arg);
} else if (arg.indexOf('--icu-data-dir') === 0) {
args.unshift(arg);
} else if (arg.indexOf('--max-old-space-size') === 0) {
args.unshift(arg);
} else if (arg.indexOf('--preserve-symlinks') === 0) {
args.unshift(arg);
} else {
count++;
args.push(arg);
}
break;
}
});
if (args.length === count + 1) {
return null;
}
if (isDebug) {
args.push('--debugger');
}
return args;
}