"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Shell = void 0; const child_process_1 = require("child_process"); const log_1 = require("../log"); const os_1 = require("os"); class Shell { constructor(args, cwd = null, stdio = null, stderr = null, after = null, silent = false) { this.lines = []; this.stdio = null; this.stderr = null; this.after = null; this.silent = false; const bin = args.shift(); this.bin = bin; this.args = args; this.stdio = stdio; this.stderr = stderr; this.silent = silent; this.after = after; this.cwd = cwd; this.log = (0, log_1.createLog)(bin); } async execute() { return new Promise((resolve, reject) => { const options = {}; if (this.cwd !== null) { options.cwd = this.cwd; } this.child = (0, child_process_1.spawn)(this.bin, this.args, options); this.log.info(`Shell: ${this.bin} ${this.args.join(' ')}`); this.child.stdout.on('data', (data) => { if (!this.silent) this.log.info(data); if (this.after !== null) this.lines.push(data); if (this.stdio !== null) { this.stdio(data); } }); this.child.stderr.on('data', (data) => { if (!this.silent) this.log.warn(data); if (this.stderr !== null) { this.stderr(data); } }); this.child.on('close', (code) => { if (this.after !== null) { this.after(this.lines.join(os_1.EOL)); } if (code === 0) { this.log.info(`Complete: ${this.bin} ${this.args.join(' ')}`); return resolve(code); } else { this.log.error(`Error executing: ${this.bin} ${this.args.join(' ')}`); return reject(code); } }); }); } kill() { this.log.warn(`Killing: ${this.bin} ${this.args.join(' ')}`); //this.child.stdin.pause(); this.child.kill(); } } exports.Shell = Shell; module.exports = { Shell }; //# sourceMappingURL=index.js.map