Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` choose default click action
13 changes: 12 additions & 1 deletion extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,18 @@
"default": false,
"scope": "resource",
"description": "%config.npm.enableScriptExplorer%"
}
},
"npm.scriptExplorerAction": {
"type": "string",
"enum": [
"open",
"run",
"debug"
],
"description": "%config.npm.scriptExplorerAction%",
"scope": "resource",
"default": "open"
}
}
},
"jsonValidation": [
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": "Define default click action.",
"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 ommitted.",
Expand Down
28 changes: 23 additions & 5 deletions extensions/npm/src/npmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,38 @@ class PackageJSON extends TreeItem {
}
}

type NpmActions = 'open' | 'run' | 'debug';

class NpmScript extends TreeItem {
task: Task;
package: PackageJSON;

constructor(context: ExtensionContext, packageJson: PackageJSON, task: Task) {
super(task.name, TreeItemCollapsibleState.None);
const config = workspace.getConfiguration();
const action: NpmActions = config.get('npm.scriptExplorerAction') || 'open';
const commandList = {
'open': {
title: 'Configure Script',
command: 'npm.openScript',
arguments: [this]
},
'run': {
title: 'Run Script',
command: 'npm.runScript',
arguments: [this]
},
'debug': {
title: 'Debug Script',
command: 'npm.debugScript',
arguments: [this]
}
};

this.contextValue = 'script';
this.package = packageJson;
this.task = task;
this.command = {
title: 'Run Script',
command: 'npm.openScript',
arguments: [this]
};
this.command = commandList[action];
this.iconPath = {
light: context.asAbsolutePath(path.join('resources', 'light', 'script.svg')),
dark: context.asAbsolutePath(path.join('resources', 'dark', 'script.svg'))
Expand Down