1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const { spawn } = require('child_process');
|
8 | const logger = require('pino')({
|
9 | prettyPrint: { colorize: true },
|
10 | });
|
11 |
|
12 | const run = torun => new Promise((resolve, reject) => {
|
13 | const command = spawn(torun, {
|
14 | shell: true,
|
15 | });
|
16 | command.stdout.on('data', (data) => {
|
17 | logger.info(`${data}`);
|
18 | });
|
19 | command.stderr.on('data', (data) => {
|
20 | logger.error(`${data}`);
|
21 | });
|
22 | command.on('close', (code) => {
|
23 | if (!code) {
|
24 | resolve();
|
25 | } else {
|
26 | logger.info(`complete with code ${code}`);
|
27 | reject(code);
|
28 | }
|
29 | });
|
30 | });
|
31 |
|
32 | module.exports = run;
|