Skip to content
27 changes: 16 additions & 11 deletions tools/release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { Builder } = require("./builder.cjs");
const cmdPrompt = require("prompt");
const colors = require("colors");
const { exec } = require("child_process");
const { execFile } = require("child_process");
const loading = require("loading-indicator");
const DEBUG = false;
const vnu = require("vnu-jar");
Expand Down Expand Up @@ -35,26 +35,30 @@ const loadOps = {
delay: 100,
};

/** @param {string} program */
function commandRunner(program) {
/**
* @param {string} file
* @param {string[]} [baseArgs]
*/
function commandRunner(file, baseArgs = []) {
/**
* @param {string} cmd
* @param {{showOutput: boolean}} [options ]
* @param {{showOutput: boolean}} [options]
*/
const runner = (cmd, options = { showOutput: false }) => {
console.log(colors.cyan(`Run: ${program} ${colors.grey(cmd)}`));
const args = [...baseArgs, ...cmd.split(/\s+/).filter(Boolean)];
console.log(colors.cyan(`Run: ${file} ${colors.grey(args.join(" "))}`));
Comment thread
marcoscaceres marked this conversation as resolved.
Outdated
if (DEBUG) {
return Promise.resolve("");
}
return toExecPromise(`${program} ${cmd}`, { ...options, timeout: 200000 });
return toExecFilePromise(file, args, { ...options, timeout: 200000 });
};
return runner;
}

const git = commandRunner("git");
const npm = commandRunner("npm");
const node = commandRunner("node");
const validator = commandRunner(`java -jar ${vnu}`);
const validator = commandRunner("java", ["-jar", vnu]);

cmdPrompt.start();

Expand Down Expand Up @@ -253,17 +257,18 @@ const Prompts = {

/**
*
* @param {string} cmd
* @param {string} file
* @param {string[]} args
* @param {{ timeout: number, showOutput: boolean }} options
* @returns {Promise<string>}
*/
function toExecPromise(cmd, { timeout, showOutput }) {
function toExecFilePromise(file, args, { timeout, showOutput }) {
return new Promise((resolve, reject) => {
const id = setTimeout(() => {
reject(new Error(`Command took too long: ${cmd}`));
reject(new Error(`Command took too long: ${file} ${args.join(" ")}`));
proc.kill("SIGTERM");
}, timeout);
const proc = exec(cmd, (err, stdout) => {
const proc = execFile(file, args, (err, stdout) => {
clearTimeout(id);
if (err) {
return reject(err);
Expand Down
Loading