Merge NPM Scripts: Added configuration option to change default click action #49282

This commit is contained in:
Erich Gamma 2018-05-28 11:09:16 +02:00
parent c6d1072a7f
commit baf3b60651
5 changed files with 44 additions and 13 deletions

View file

@ -1,6 +1,6 @@
# Node npm
**Notice** This is a an extension that is bundled with Visual Studio Code.
**Notice** This is a an extension that is bundled with Visual Studio Code.
This extension supports running npm scripts defined in the `package.json` as [tasks](https://code.visualstudio.com/docs/editor/tasks). Scripts with the name 'build', 'compile', or 'watch'
are treated as build tasks.
@ -15,3 +15,4 @@ For more information about auto detection of Tasks pls see the [documentation](h
- `npm.packageManager` the package manager used to run the scripts: `npm` or `yarn`, the default is `npm`.
- `npm.exclude` glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'.
- `npm.enableScriptExplorer` enable an explorer view for npm scripts.
- `npm.scriptExplorerAction` the default click action: `open` or `run`, the default is `open`.

View file

@ -98,19 +98,20 @@
},
{
"command": "npm.runScript",
"when": "view == npm && viewItem == script",
"group": "inline"
"when": "view == npm && viewItem == script",
"group": "inline"
},
{
"command": "npm.runScript",
"when": "view == npm && viewItem == debugScript",
"group": "inline"
"when": "view == npm && viewItem == debugScript",
"group": "inline"
},
{
"command": "npm.debugScript",
"when": "view == npm && viewItem == debugScript",
"group": "inline"
}, {
"when": "view == npm && viewItem == debugScript",
"group": "inline"
},
{
"command": "npm.debugScript",
"when": "view == npm && viewItem == script",
"group": "navigation@3"
@ -164,6 +165,16 @@
"default": false,
"scope": "resource",
"description": "%config.npm.enableScriptExplorer%"
},
"npm.scriptExplorerAction": {
"type": "string",
"enum": [
"open",
"run"
],
"description": "%config.npm.scriptExplorerAction%",
"scope": "window",
"default": "open"
}
}
},

View file

@ -6,6 +6,7 @@
"config.npm.packageManager": "The package manager used to run scripts.",
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts.",
"config.npm.scriptExplorerAction": "The default click action used in the scripts explorer: 'open' or 'run', the default is 'open'.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
"taskdef.script": "The npm script to customize.",
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",

View file

@ -25,6 +25,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
treeDataProvider.refresh();
}
}
if (e.affectsConfiguration('npm.scriptExplorerAction')) {
if (treeDataProvider) {
treeDataProvider.refresh();
}
}
});
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
}

View file

@ -65,23 +65,36 @@ class PackageJSON extends TreeItem {
}
}
type ExplorerCommands = 'open' | 'run';
class NpmScript extends TreeItem {
task: Task;
package: PackageJSON;
constructor(context: ExtensionContext, packageJson: PackageJSON, task: Task) {
super(task.name, TreeItemCollapsibleState.None);
const command: ExplorerCommands = workspace.getConfiguration('npm').get<ExplorerCommands>('scriptExplorerAction') || 'open';
const commandList = {
'open': {
title: 'Edit Script',
command: 'npm.openScript',
arguments: [this]
},
'run': {
title: 'Run Script',
command: 'npm.runScript',
arguments: [this]
}
};
this.contextValue = 'script';
if (task.group && task.group === TaskGroup.Rebuild) {
this.contextValue = 'debugScript';
}
this.package = packageJson;
this.task = task;
this.command = {
title: 'Run Script',
command: 'npm.openScript',
arguments: [this]
};
this.command = commandList[command];
if (task.group && task.group === TaskGroup.Clean) {
this.iconPath = {
light: context.asAbsolutePath(path.join('resources', 'light', 'prepostscript.svg')),