Skip to content

Commit

Permalink
Merge NPM Scripts: Added configuration option to change default click…
Browse files Browse the repository at this point in the history
… action #49282
  • Loading branch information
egamma committed May 28, 2018
1 parent c6d1072 commit baf3b60
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
3 changes: 2 additions & 1 deletion extensions/npm/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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`.
25 changes: 18 additions & 7 deletions extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions extensions/npm/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 5 additions & 0 deletions extensions/npm/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
23 changes: 18 additions & 5 deletions extensions/npm/src/npmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down

0 comments on commit baf3b60

Please sign in to comment.