mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Support to run npm install from a package node
This commit is contained in:
parent
a50384a007
commit
83cb1d7799
|
@ -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"
|
||||
|
|
|
@ -14,5 +14,6 @@
|
|||
"command.refresh": "Refresh",
|
||||
"command.run": "Run",
|
||||
"command.debug": "Debug",
|
||||
"command.openScript": "Open"
|
||||
"command.openScript": "Open",
|
||||
"command.runInstall": "Run Install"
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue