sda
Version:
Software development assistant
71 lines • 2.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const Log_1 = __importDefault(require("../Log"));
const getAbsolutePath_1 = __importDefault(require("../utils/getAbsolutePath"));
const processCommandParams_1 = __importDefault(require("./processCommandParams"));
function getCommands(environment, commandNames, params) {
const cmds = [];
for (const cmdName of commandNames) {
const cmd = getCommand(environment, cmdName, params);
if (cmd) {
cmds.push(cmd);
}
}
return cmds;
}
exports.default = getCommands;
function getCommand(environment, cmdName, params) {
const template = environment.template;
const commandName = getCommandName(cmdName, template);
if (!commandName) {
Log_1.default.error(`Command "${cmdName}" not found in template "${template.id}"`);
return undefined;
}
let command = normalizeCommand(template.commands[commandName]);
command = processCommandParams_1.default(command, params);
const cwd = command.cwd ? getAbsolutePath_1.default(command.cwd, environment.path) : environment.path;
return {
id: commandName,
cmd: command.cmd,
cwd,
timeout: parseInt(command.timeout, 10) || undefined
};
}
function normalizeCommand(command) {
if (util_1.isString(command)) {
command = { cmd: [command] };
}
else if (util_1.isArray(command)) {
command = { cmd: command };
}
else if (util_1.isString(command.cmd)) {
command.cmd = [command.cmd];
}
else if (util_1.isString(command.filePath)) {
let filePath = `"${command.filePath}"`;
if (util_1.isString(command.interpreter)) {
if (command.interpreter === 'powershell') {
filePath = `${command.interpreter} -File ${filePath}`;
}
else {
filePath = `${command.interpreter} ${filePath}`;
}
}
command.cmd = [filePath];
}
return command;
}
function getCommandName(commandName, template) {
if (template.commands[commandName]) {
return commandName;
}
if (template.aliases && template.aliases[commandName] && template.commands[template.aliases[commandName]]) {
return template.aliases[commandName];
}
return '';
}
//# sourceMappingURL=getCommands.js.map