UNPKG

chimp

Version:

Your development companion for doing quality, faster.

31 lines (30 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execQuietly = void 0; const tslib_1 = require("tslib"); const shelljs_1 = tslib_1.__importDefault(require("shelljs")); const debug_1 = tslib_1.__importDefault(require("debug")); const debug = (0, debug_1.default)('execQuietly'); async function execQuietly(command, options, errorMessage = '') { return new Promise((resolve, reject) => { const child = shelljs_1.default.exec(command, Object.assign(Object.assign({}, options), { silent: !debug.enabled, async: true })); let stdoutData = ''; let stderrData = ''; child.stdout.on('data', (data) => { stdoutData += data; }); child.stderr.on('data', (data) => { stderrData += data; }); // Listen for the exit event to get the exit code child.on('exit', (code) => { if (code === 0) { resolve(); } else { reject(new Error(`${stdoutData} ${errorMessage}: ${stderrData} ${command}`)); } }); }); } exports.execQuietly = execQuietly;