"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.promisifyProcess = void 0;
function promisifyProcess(p, opts = {}) {
    return new Promise((resolve, reject) => {
        var _a, _b, _c, _d;
        let stdout = '';
        let stderr = '';
        (_b = (_a = p.stdout) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, 'data', opts.onStdout ||
            ((data) => {
                console.log(`${data}`);
                stdout += data;
            }));
        (_d = (_c = p.stderr) === null || _c === void 0 ? void 0 : _c.on) === null || _d === void 0 ? void 0 : _d.call(_c, '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;
