@naturalcycles/ktlint
Version:
ktlint, conveniently published to npm registry
38 lines (37 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCommand = runCommand;
exports.runCommandSafe = runCommandSafe;
const node_child_process_1 = require("node:child_process");
function runCommand(command, args = [], opt = {}) {
console.log([command, ...args].join(' '));
const p = (0, node_child_process_1.spawn)(command, [...args], {
stdio: 'inherit',
shell: true,
...opt,
});
p.on('close', code => {
if (code) {
console.log(`${command} exited with code ${code}`);
}
process.exit(code || 0);
});
}
/**
* Throws error on failure.
*/
async function runCommandSafe(command, args = [], opt = {}) {
console.log([command, ...args].join(' '));
return await new Promise((resolve, reject) => {
const p = (0, node_child_process_1.spawn)(command, [...args], {
stdio: 'inherit',
shell: true,
...opt,
});
p.on('close', code => {
if (!code)
return resolve();
reject(new Error(`${command} exited with code ${code}`));
});
});
}