in src/main.ts [360:417]
function pickScriptToExecute(descriptions: ScriptCommandDescription[], command: string[], allowAll = false, alwaysRunInputWindow = false) {
const scriptList: Script[] = [];
const isScriptCommand = command[0] === 'run-script';
if (allowAll && descriptions.length > 1) {
scriptList.push(createAllCommand(scriptList, isScriptCommand));
}
for (const s of descriptions) {
let label = s.name;
if (s.relativePath) {
label = `${s.relativePath} - ${label}`;
}
if (isMultiRoot()) {
const root = workspace.getWorkspaceFolder(Uri.file(s.absolutePath));
if (root) {
label = `${root.name}: ${label}`;
}
}
scriptList.push({
label: label,
description: s.cmd,
scriptName: s.name,
cwd: s.absolutePath,
execute(this: Script) {
let script = this.scriptName;
// quote the script name, when it contains white space
if (/\s/g.test(script)) {
script = `"${script}"`;
}
// Create copy of command to ensure that we always get the correct command when the script is rerun.
const cmd = Array.from(command);
if (isScriptCommand) {
lastScript = this;
//Add script name to command array
cmd.push(script);
}
runNpmCommand(cmd, this.cwd, alwaysRunInputWindow);
}
});
}
if (scriptList.length === 1) {
scriptList[0].execute();
return;
} else if (scriptList.length === 0) {
if (isScriptCommand) {
window.showErrorMessage(`Failed to find script with "${command[1]}" command`);
} else {
window.showErrorMessage(`Failed to find handler for "${command[0]}" command`);
}
return;
}
window.showQuickPick(scriptList).then(script => {
if (script) {
script.execute();
}
});
}