added config option whether the explorer should be enabled.
This commit is contained in:
parent
bb1119e0b1
commit
48b0ec47da
5 changed files with 42 additions and 13 deletions
|
@ -14,3 +14,4 @@ For more information about auto detection of Tasks pls see the [documentation](h
|
||||||
- `npm.runSilent` run npm script with the `--silent` option, the default is `false`.
|
- `npm.runSilent` run npm script with the `--silent` option, the default is `false`.
|
||||||
- `npm.packageManager` the package manager used to run the scripts: `npm` or `yarn`, the default is `npm`.
|
- `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.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 when the workspace contains a 'package.json' file.
|
||||||
|
|
|
@ -96,7 +96,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"id": "npm",
|
"id": "npm",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -138,6 +137,12 @@
|
||||||
},
|
},
|
||||||
"description": "%config.npm.exclude%",
|
"description": "%config.npm.exclude%",
|
||||||
"scope": "resource"
|
"scope": "resource"
|
||||||
|
},
|
||||||
|
"npm.enableScriptExplorer": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"scope": "resource",
|
||||||
|
"description": "%config.npm.enableScriptExplorer%"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -170,4 +175,4 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
"config.npm.runSilent": "Run npm commands with the `--silent` option.",
|
"config.npm.runSilent": "Run npm commands with the `--silent` option.",
|
||||||
"config.npm.packageManager": "The package manager used to run scripts.",
|
"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.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
|
||||||
|
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts, when the workspace contains a 'package.json' file.",
|
||||||
"npm.parseError": "Npm task detection: failed to parse the file {0}",
|
"npm.parseError": "Npm task detection: failed to parse the file {0}",
|
||||||
"taskdef.script": "The npm script to customize.",
|
"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.",
|
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be ommitted.",
|
||||||
|
|
|
@ -12,12 +12,18 @@ const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
import { addJSONProviders } from './features/jsonContributions';
|
import { addJSONProviders } from './features/jsonContributions';
|
||||||
import { NpmScriptsTreeDataProvider } from './npmView';
|
import { NpmScriptsTreeDataProvider } from './npmView';
|
||||||
import { provideNpmScripts, hasNpmScripts } from './tasks';
|
import { provideNpmScripts, hasNpmScripts, explorerIsEnabled } from './tasks';
|
||||||
|
|
||||||
let taskProvider: vscode.Disposable | undefined;
|
let taskProvider: vscode.Disposable | undefined;
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||||
|
taskProvider = registerTaskProvider(context);
|
||||||
|
configureHttpRequest();
|
||||||
|
vscode.workspace.onDidChangeConfiguration(() => configureHttpRequest());
|
||||||
|
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
||||||
if (vscode.workspace.workspaceFolders) {
|
if (vscode.workspace.workspaceFolders) {
|
||||||
let provider: vscode.TaskProvider = {
|
let provider: vscode.TaskProvider = {
|
||||||
provideTasks: () => {
|
provideTasks: () => {
|
||||||
|
@ -27,19 +33,21 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
taskProvider = vscode.workspace.registerTaskProvider('npm', provider);
|
let disposable = vscode.workspace.registerTaskProvider('npm', provider);
|
||||||
|
registerExplorer(context, provider);
|
||||||
|
return disposable;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function registerExplorer(context: vscode.ExtensionContext, provider: vscode.TaskProvider) {
|
||||||
|
if (explorerIsEnabled()) {
|
||||||
let treeDataProvider = vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context, provider, localize));
|
let treeDataProvider = vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context, provider, localize));
|
||||||
context.subscriptions.push(treeDataProvider);
|
context.subscriptions.push(treeDataProvider);
|
||||||
|
|
||||||
if (await hasNpmScripts()) {
|
if (await hasNpmScripts()) {
|
||||||
vscode.commands.executeCommand('setContext', 'hasNpmScripts', true);
|
vscode.commands.executeCommand('setContext', 'hasNpmScripts', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureHttpRequest();
|
|
||||||
vscode.workspace.onDidChangeConfiguration(() => configureHttpRequest());
|
|
||||||
|
|
||||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function configureHttpRequest() {
|
function configureHttpRequest() {
|
||||||
|
|
|
@ -48,6 +48,20 @@ export function getPackageManager(folder: WorkspaceFolder): string {
|
||||||
return workspace.getConfiguration('npm', folder.uri).get<string>('packageManager', 'npm');
|
return workspace.getConfiguration('npm', folder.uri).get<string>('packageManager', 'npm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function explorerIsEnabled(): boolean {
|
||||||
|
let folders = workspace.workspaceFolders;
|
||||||
|
if (!folders) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < folders.length; i++) {
|
||||||
|
let folder = folders[i];
|
||||||
|
if (workspace.getConfiguration('npm', folder.uri).get<boolean>('enableScriptExplorer') === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export async function hasNpmScripts(): Promise<boolean> {
|
export async function hasNpmScripts(): Promise<boolean> {
|
||||||
let folders = workspace.workspaceFolders;
|
let folders = workspace.workspaceFolders;
|
||||||
if (!folders) {
|
if (!folders) {
|
||||||
|
@ -56,7 +70,7 @@ export async function hasNpmScripts(): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < folders.length; i++) {
|
for (let i = 0; i < folders.length; i++) {
|
||||||
let folder = folders[i];
|
let folder = folders[i];
|
||||||
if (isEnabled(folder)) {
|
if (isAutoDetectionEnabled(folder)) {
|
||||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||||
if (paths.length > 0) {
|
if (paths.length > 0) {
|
||||||
|
@ -81,7 +95,7 @@ export async function provideNpmScripts(localize: any): Promise<Task[]> {
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < folders.length; i++) {
|
for (let i = 0; i < folders.length; i++) {
|
||||||
let folder = folders[i];
|
let folder = folders[i];
|
||||||
if (isEnabled(folder)) {
|
if (isAutoDetectionEnabled(folder)) {
|
||||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||||
for (let j = 0; j < paths.length; j++) {
|
for (let j = 0; j < paths.length; j++) {
|
||||||
|
@ -98,7 +112,7 @@ export async function provideNpmScripts(localize: any): Promise<Task[]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEnabled(folder: WorkspaceFolder): boolean {
|
function isAutoDetectionEnabled(folder: WorkspaceFolder): boolean {
|
||||||
return workspace.getConfiguration('npm', folder.uri).get<AutoDetect>('autoDetect') === 'on';
|
return workspace.getConfiguration('npm', folder.uri).get<AutoDetect>('autoDetect') === 'on';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue