"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.promisifyProcess = void 0;
function promisifyProcess(p, opts = {}) {
    return new Promise((resolve, reject) => {
        let stdout = '';
        let stderr = '';
        p.stdout &&
            p.stdout.on('data', opts.onStdout ||
                ((data) => {
                    console.log(data + '');
                    stdout += data;
                }));
        p.stderr &&
            p.stderr.on('data', opts.onStderr ||
                ((data) => {
                    console.error(data + '');
                    stderr += data;
                }));
        p.on('error', reject);
        p.on('exit', (exitCode) => {
            exitCode === 0
                ? resolve(exitCode)
                : reject(new Error(stderr || String(exitCode)));
        });
    });
}
exports.promisifyProcess = promisifyProcess;
