Merge NPM Scripts: Added configuration option to change default click action #49282
This commit is contained in:
parent
c6d1072a7f
commit
baf3b60651
5 changed files with 44 additions and 13 deletions
|
@ -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`.
|
||||
|
|
|
@ -110,7 +110,8 @@
|
|||
"command": "npm.debugScript",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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')),
|
||||
|
|
Loading…
Reference in a new issue