datasquirel/dist/package-shared/utils/execute.js
Benjamin Toby c37d105dee Updates
2025-07-09 20:30:45 +01:00

41 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = execute;
const child_process_1 = require("child_process");
function execute(cmd, options) {
function runCmd(cmd) {
try {
const res = (0, child_process_1.execSync)(cmd, Object.assign({ encoding: "utf-8" }, options));
if (typeof res == "string") {
return res.trim();
}
else {
return undefined;
}
}
catch (error) {
console.log(`Execute Run Error =>`, error.message);
console.log(`Execute CMD =>`, cmd);
return undefined;
}
}
try {
if (typeof cmd == "string") {
return runCmd(cmd);
}
else if (Array.isArray(cmd)) {
let resArr = [];
for (let i = 0; i < cmd.length; i++) {
const singleCmd = cmd[i];
const res = runCmd(singleCmd);
resArr.push(res);
}
return resArr;
}
}
catch (error) {
console.log(`Execute Error =>`, error.message);
return undefined;
}
}