Skip to content

Commit

Permalink
supports ng run command for angular cli projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandi Barr committed May 27, 2021
1 parent 8d12d5f commit 4d6e53f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 33 deletions.
39 changes: 38 additions & 1 deletion apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@
"menus": {
"explorer/context": [
{
"when": "isAngularWorkspace && config.nxConsole.enableGenerateFromContextMenu || isNxWorkspace && config.nxConsole.enableGenerateFromContextMenu",
"when": "isAngularWorkspace && config.nxConsole.enableGenerateFromContextMenu",
"command": "ng.generate.ui.fileexplorer",
"group": "explorerContext"
},
{
"when": "isAngularWorkspace && config.nxConsole.enableGenerateFromContextMenu",
"command": "ng.run.fileexplorer",
"group": "explorerContext"
},
{
"when": "isNxWorkspace && config.nxConsole.enableGenerateFromContextMenu",
"command": "nx.generate.ui.fileexplorer",
"group": "explorerContext"
},
Expand Down Expand Up @@ -82,6 +92,14 @@
}
],
"commandPalette": [
{
"command": "ng.generate.ui.fileexplorer",
"when": "false"
},
{
"command": "ng.run.fileexplorer",
"when": "false"
},
{
"command": "nx.generate.ui.fileexplorer",
"when": "false"
Expand Down Expand Up @@ -114,6 +132,10 @@
"command": "ng.test",
"when": "isAngularWorkspace"
},
{
"command": "ng.run",
"when": "isAngularWorkspace"
},
{
"command": "ng.lint.ui",
"when": "isAngularWorkspace"
Expand Down Expand Up @@ -300,6 +322,11 @@
"title": "test",
"command": "ng.test"
},
{
"category": "ng",
"title": "run",
"command": "ng.run"
},
{
"category": "ng",
"title": "lint (ui)",
Expand Down Expand Up @@ -335,6 +362,16 @@
"title": "generate (ui)",
"command": "ng.generate.ui"
},
{
"category": "ng",
"title": "ng generate (ui)",
"command": "ng.generate.ui.fileexplorer"
},
{
"category": "ng",
"title": "ng run",
"command": "ng.run.fileexplorer"
},
{
"category": "Nx",
"title": "lint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class WorkspaceCodeLensProvider implements CodeLensProvider {
resolveCodeLens(lens: CodeLens): CodeLens | Promise<CodeLens> | null {
if (lens instanceof ProjectCodeLens) {
const command: Command = {
command: 'nx.run',
command: `${lens.workspaceType}.run`,
title: lens.configuration
? `${lens.workspaceType} run ${lens.project}:${lens.target}:${lens.configuration}`
: `${lens.workspaceType} run ${lens.project}:${lens.target}`,
Expand Down
59 changes: 28 additions & 31 deletions libs/vscode/tasks/src/lib/cli-task-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,30 @@ export function registerCliTaskCommands(
);
});

commands.registerCommand(
'nx.run',
(project?: string, target?: string, configuration?: string) => {
let flags;
if (configuration) {
flags = [`-c ${configuration}`];
} else if (project && target) {
// don't prompt for flags when project and target are already specified
flags = [];
['ng', 'nx'].forEach(cli => {
commands.registerCommand(
`${cli}.run`,
(project?: string, target?: string, configuration?: string) => {
selectCliCommandAndPromptForFlags('run', project, target, configuration)
}
selectCliCommandAndPromptForFlags('run', project, target, flags)
}
);
commands.registerCommand(`nx.run.fileexplorer`, (uri: Uri) =>
selectCliCommandAndPromptForFlags('run', getCliProjectFromUri(uri))
);
);
commands.registerCommand(`${cli}.run.fileexplorer`, (uri: Uri) =>
selectCliCommandAndPromptForFlags('run', getCliProjectFromUri(uri))
);

commands.registerCommand(`ng.generate`, () =>
selectSchematicAndPromptForFlags()
);
commands.registerCommand(`${cli}.generate`, () =>
selectSchematicAndPromptForFlags()
);

commands.registerCommand(`ng.generate.ui`, () =>
selectCliCommandAndShowUi('generate', context.extensionPath)
);
commands.registerCommand(`nx.generate`, () =>
selectSchematicAndPromptForFlags()
);
commands.registerCommand(`${cli}.generate.ui`, () =>
selectCliCommandAndShowUi('generate', context.extensionPath)
);

commands.registerCommand(`${cli}.generate.ui.fileexplorer`, (uri: Uri) =>
selectCliCommandAndShowUi('generate', context.extensionPath, uri)
);
})

commands.registerCommand(`nx.generate.ui`, () =>
selectCliCommandAndShowUi('generate', context.extensionPath)
);
commands.registerCommand(`nx.generate.ui.fileexplorer`, (uri: Uri) =>
selectCliCommandAndShowUi('generate', context.extensionPath, uri)
);
}

function selectCliCommandAndShowUi(
Expand Down Expand Up @@ -117,8 +107,15 @@ async function selectCliCommandAndPromptForFlags(
command: string,
projectName?: string,
target?: string,
flags?: string[]
configuration?: string
) {
let flags: string[] | undefined;
if (configuration) {
flags = [`--configuration=${configuration}`];
} else if (projectName && target) {
// don't prompt for flags when project and target are already specified
flags = [];
}
const { validWorkspaceJson, json, workspaceType } = verifyWorkspace();

if (!projectName) {
Expand Down

0 comments on commit 4d6e53f

Please sign in to comment.