UNPKG

700 BJavaScriptView Raw
1/*
2 * File: shell.js
3 * File Created: Saturday, 8th December 2018 6:23:58 pm
4 * Author: ChegCheng Wan (chengcheng.st@gmail.com)
5 */
6
7const { spawn } = require('child_process');
8const logger = require('pino')({
9 prettyPrint: { colorize: true },
10});
11
12const 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
32module.exports = run;