exec.dev.js 719 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 22 23 24 25 26 27 28 29
"use strict";

var _require = require('child_process'),
    spawn = _require.spawn;

var spawnWin = require('cross-spawn');

module.exports = function exec(command, args, opts) {
  return new Promise(function (resolve, reject) {
    var 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', function (err) {
      console.log(err);
      reject(err);
    });
    child.once('close', function (code) {
      if (code === 1) {
        process.exit(1);
      } else {
        resolve();
      }
    });
  });
};