-
Notifications
You must be signed in to change notification settings - Fork 0
/
adaptor.ts
52 lines (42 loc) · 1.31 KB
/
adaptor.ts
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
#!/usr/bin/env node
import * as child from 'child_process';
import * as path from 'path';
import { promisify } from 'util';
import { SpawnOptions } from 'child_process';
const spawn = <(command: string, opts: SpawnOptions) => Promise<child.ChildProcess>>promisify(child.spawn);
const options: SpawnOptions = {
stdio: 'inherit',
shell: true
};
const exe = async (expression) => {
if (verboseEnabled) {
console.log('[spypkg] Executing: ' + expression);
}
return await spawn(expression, options)
.then((onfulfilled) => {
if (onfulfilled.stdout) {
console.log(onfulfilled.stdout);
}
if (onfulfilled.stderr) {
console.log(onfulfilled.stderr);
}
})
.catch((reason) => {
console.log(reason);
});
};
let verboseEnabled: boolean;
let argument: string = '';
const ext = process.platform === 'win32' ? '.cmd' : '';
const command = path.join(process.cwd(), 'node_modules/.bin/', process.argv[2].toString() + ext);
// prepare argv values into a flat argument
for (let j = 3; j < process.argv.length; j++) {
if (process.argv[j] === '--verbose') {
verboseEnabled = true;
} else {
argument += ' ' + process.argv[j];
}
}
argument = argument.trimLeft();
// let prefix: string = (process.platform === 'win32') ? 'cmd /c' : '';
exe(command + ' ' + argument);