exec.js 654 Bytes
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
const { spawn } = require('child_process');
const spawnWin = require('cross-spawn');
module.exports = function exec(command, args, opts) {
  return new Promise((resolve, reject) => {
    const child =
      process.platform === 'win32'
        ? spawnWin(command, args, Object.assign({ stdio: 'inherit', env: process.env }, opts))
        : spawn(command, args, Object.assign({ stdio: 'inherit', env: process.env }, opts));
    child.once('error', (err) => {
      console.log(err);
      reject(err);
    });
    child.once('close', (code) => {
      if (code === 1) {
        process.exit(1);
      } else {
        resolve();
      }
    });
  });
};