totvs-dtsenv-cli
Version:
TOTVS Datasul Environment Command Line
35 lines (34 loc) • 1.4 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process = __importStar(require("child_process"));
class CommandUtils {
static execCommandSync(command, args, logError = true) {
const { status, error, stderr, stdout } = child_process.spawnSync(command, args, {});
if (status != 0 && (command != 'robocopy' && status > 1)) {
if (logError)
console.log(`Command failed: ${command} ${args.map(x => JSON.stringify(x)).join(', ')}`);
if (error) {
if (logError)
console.log('Error: ' + (error ? error.message : 'undefined'));
throw error;
}
else {
if (logError)
console.log(`STDERR:\n${stderr}`);
throw stderr.toString('utf8');
}
}
return stdout.toString('utf8');
}
static execCommand(command, args, callback) {
const child = child_process.execFile(command, args, callback);
}
}
exports.default = CommandUtils;