in src/main.ts [506:548]
function commandDescriptionsInPackage(param: string[], packagePath: string, descriptions: ScriptCommandDescription[]) {
const absolutePath = packagePath;
const fileUri = Uri.file(absolutePath);
const workspaceFolder = workspace.getWorkspaceFolder(fileUri);
let rootUri: Uri | undefined = undefined;
let relativePath: string | undefined = undefined;
if (workspaceFolder) {
rootUri = workspaceFolder.uri;
relativePath = absolutePath.substring(rootUri.fsPath.length + 1);
}
const cmd = param[0];
const name = param[1];
if (cmd === 'run-script') {
try {
const fileName = path.join(packagePath, 'package.json');
const contents = fs.readFileSync(fileName).toString();
const json = JSON.parse(contents);
if (json.scripts) {
const jsonScripts = json.scripts;
Object.keys(jsonScripts).forEach(key => {
if (!name || key === name) {
descriptions.push({
absolutePath: absolutePath,
relativePath: relativePath,
name: `${key}`,
cmd: `${cmd} ${jsonScripts[key]}`
});
}
});
}
} catch (e) {
}
} else {
descriptions.push({
absolutePath: absolutePath,
relativePath: relativePath,
name: `${cmd}`,
cmd: `npm ${cmd}`
});
}
}