"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.exec = void 0;
const child_process_1 = require("child_process");
const log_1 = require("./log");
const log = new log_1.Logger('child-process');
const exec = (cmd, argv, options) => new Promise((resolve, reject) => {
    const cp = child_process_1.spawn(cmd, argv, options);
    cp.stdout.on('data', (msg) => console.info(msg.toString()));
    cp.stderr.on('data', (err) => console.warn(err.toString()));
    cp.on('error', (err) => {
        log.error('spawn child process error: %s', err.stack);
        reject(err);
    });
    cp.on('close', (code) => {
        if (code) {
            return reject(new Error(`Execting ${cmd} returns: ${code}`));
        }
    });
    return resolve(cp);
});
exports.exec = exec;
