Support to run npm install from a package node

This commit is contained in:
Erich Gamma 2018-05-28 14:41:08 +02:00
parent a50384a007
commit 83cb1d7799
4 changed files with 30 additions and 4 deletions

View file

@ -63,6 +63,10 @@
"command": "npm.openScript",
"title": "%command.openScript%"
},
{
"command": "npm.runInstall",
"title": "%command.runInstall%"
},
{
"command": "npm.refresh",
"title": "%command.refresh%",
@ -84,9 +88,13 @@
{
"command": "npm.openScript",
"when": "view == npm && viewItem == packageJSON",
"group": "navigation"
"group": "navigation@1"
},
{
"command": "npm.runInstall",
"when": "view == npm && viewItem == packageJSON",
"group": "navigation@2"
}, {
"command": "npm.openScript",
"when": "view == npm && viewItem == script",
"group": "navigation@1"

View file

@ -14,5 +14,6 @@
"command.refresh": "Refresh",
"command.run": "Run",
"command.debug": "Debug",
"command.openScript": "Open"
"command.openScript": "Open",
"command.runInstall": "Run Install"
}

View file

@ -11,7 +11,10 @@ import {
WorkspaceFolder, commands, debug, window, workspace, Selection, TaskGroup
} from 'vscode';
import { visit, JSONVisitor } from 'jsonc-parser';
import { NpmTaskDefinition, getPackageJsonUriFromTask, getScripts, isWorkspaceFolder, getPackageManager, getTaskName } from './tasks';
import {
NpmTaskDefinition, getPackageJsonUriFromTask, getScripts,
isWorkspaceFolder, getPackageManager, getTaskName, createTask
} from './tasks';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@ -133,6 +136,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
subscriptions.push(commands.registerCommand('npm.debugScript', this.debugScript, this));
subscriptions.push(commands.registerCommand('npm.openScript', this.openScript, this));
subscriptions.push(commands.registerCommand('npm.refresh', this.refresh, this));
subscriptions.push(commands.registerCommand('npm.runInstall', this.runInstall, this));
}
private scriptIsValid(scripts: any, task: Task): boolean {
@ -258,6 +262,19 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
return scriptOffset;
}
private async runInstall(selection: PackageJSON) {
let uri: Uri | undefined = undefined;
if (selection instanceof PackageJSON) {
uri = selection.resourceUri;
}
if (!uri) {
return;
}
let task = createTask('install', 'install', selection.folder.workspaceFolder, uri, []);
workspace.executeTask(task);
}
private async openScript(selection: PackageJSON | NpmScript) {
let uri: Uri | undefined = undefined;
if (selection instanceof PackageJSON) {

View file

@ -205,7 +205,7 @@ export function getTaskName(script: string, relativePath: string | undefined) {
return script;
}
function createTask(script: string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, matcher?: any): Task {
export function createTask(script: string, cmd: string, folder: WorkspaceFolder, packageJsonUri: Uri, matcher?: any): Task {
function getCommandLine(folder: WorkspaceFolder, cmd: string): string {
let packageManager = getPackageManager(folder);