-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun.js
executable file
·58 lines (44 loc) · 1.38 KB
/
run.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
#!/usr/bin/env node
const path = require('path');
const process = require('process');
const { spawn } = require('child_process');
const { version } = require('./package.json');
/* eslint-disable no-magic-numbers */
if (process.argv.includes('-v')) {
console.log(version);
process.exit(0);
}
const [ major, minor ] = process.version
.slice(1)
.split('.')
.map(x => Number(x));
const supported = major > 12 ||
(major === 12 && minor >= 10);
if (!supported) {
console.error('Error: Usupported node version.\nPlease use node >= 12.10.0 to run hq.');
process.exit(1);
}
const jsModules = major < 14;
const args = [ '--no-warnings' ];
if (jsModules) args.push('--experimental-modules');
const postArgs = [];
const buildIndex = process.argv.indexOf('build');
if (buildIndex !== -1) {
postArgs.push('build');
const buildArg = process.argv[buildIndex + 1];
if (buildArg) postArgs.push(buildArg);
}
const verbose = process.argv.includes('--verbose');
if (verbose) postArgs.push('--verbose');
console.log(`(c) hqjs @ ${version}`);
const hq = spawn(
process.argv0,
[ ...args, path.resolve(__dirname, 'index.mjs'), ...postArgs ],
{
cwd: path.resolve(),
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ],
},
);
hq.stdout.on('data', data => console.log(String(data)));
hq.stderr.on('data', data => console.error(String(data)));
hq.on('message', data => console.error(String(data)));