system-commands
Version:
Run system commands in Node.js
19 lines • 779 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("util");
var child_process_1 = require("child_process");
var runCommand = util_1.promisify(child_process_1.exec);
var removeLastNewline = function (str) {
return str.replace(/\n$/, '');
};
module.exports = function (command, maxBuffer) {
return command === ''
? Promise.resolve('')
: runCommand(command, maxBuffer === undefined ? undefined : { maxBuffer: maxBuffer }).then(function (_a) {
var stdout = _a.stdout;
return removeLastNewline(typeof stdout === 'string' ? stdout : '');
}).catch(function (error) {
return Promise.reject(removeLastNewline(error.stderr));
});
};
//# sourceMappingURL=index.js.map