2019-06-09 00:51:00 +00:00
|
|
|
'use strict';
|
2024-04-06 23:18:15 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.execRaw = void 0;
|
|
|
|
exports.execRaw = require('child_process').exec;
|
2018-03-15 18:50:36 +00:00
|
|
|
/**
|
|
|
|
* Promisified child_process.exec
|
|
|
|
*
|
|
|
|
* @param cmd
|
|
|
|
* @param arg
|
|
|
|
* @param opts See child_process.exec node docs
|
|
|
|
* @param {stream.Writable} opts.stdout If defined, child process stdout will be piped to it.
|
|
|
|
* @param {stream.Writable} opts.stderr If defined, child process stderr will be piped to it.
|
|
|
|
*
|
|
|
|
* @returns {Promise<{ stdout: string, stderr: stderr }>}
|
|
|
|
*/
|
|
|
|
async function exec(...args) {
|
2019-06-09 00:51:00 +00:00
|
|
|
let cmd = args[0];
|
|
|
|
let argz = null;
|
|
|
|
let opts = null;
|
|
|
|
if (typeof args[1] === 'object' && Array.isArray(args[1])) {
|
|
|
|
argz = args[1];
|
|
|
|
}
|
|
|
|
if (argz === null && typeof args[1] === 'object') {
|
|
|
|
opts = args[1];
|
|
|
|
}
|
|
|
|
else if (typeof args[2] === 'object') {
|
|
|
|
opts = args[2];
|
|
|
|
}
|
|
|
|
if (opts === null) {
|
|
|
|
opts = { maxBuffer: 1024 * 1024 };
|
|
|
|
}
|
2018-03-15 18:50:36 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2024-04-06 23:18:15 +00:00
|
|
|
const child = (0, exports.execRaw)(cmd, opts, (err, stdout, stderr) => err ? reject(err) : resolve({
|
2019-06-09 00:51:00 +00:00
|
|
|
stdout,
|
|
|
|
stderr
|
|
|
|
}));
|
2018-03-15 18:50:36 +00:00
|
|
|
if (opts.stdout) {
|
|
|
|
child.stdout.pipe(opts.stdout);
|
|
|
|
}
|
|
|
|
if (opts.stderr) {
|
|
|
|
child.stderr.pipe(opts.stderr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-09 01:43:14 +00:00
|
|
|
module.exports.exec = exec;
|
2019-06-09 00:51:00 +00:00
|
|
|
//# sourceMappingURL=index.js.map
|