Skip to content

Commit

Permalink
feat: add context menu to execute task without Nx cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhavat committed Dec 16, 2022
1 parent c6c3997 commit 3216ffd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
"when": "view == nxProjects && viewItem == target",
"group": "inline"
},
{
"command": "nxConsole.runTaskSkipNxCache",
"when": "view == nxProjects && viewItem == target",
"group": "navigation"
},
{
"command": "nx.graph.focus.button",
"when": "view == nxProjects && viewItem == project && isNxWorkspace",
Expand Down Expand Up @@ -182,6 +187,10 @@
"command": "nxConsole.runTask",
"when": "false"
},
{
"command": "nxConsole.runTaskSkipNxCache",
"when": "false"
},
{
"command": "nxConsole.revealInExplorer",
"when": "false"
Expand Down Expand Up @@ -415,6 +424,10 @@
"title": "Execute task",
"icon": "$(play)"
},
{
"command": "nxConsole.runTaskSkipNxCache",
"title": "Execute task without Nx cache"
},
{
"category": "ng",
"title": "Run Target",
Expand Down
18 changes: 17 additions & 1 deletion libs/vscode/nx-project-view/src/lib/nx-project-tree-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {

export type ViewItem = ListViewItem | TreeViewItem | AutomaticViewItem;

interface NxOptionalFlags {
skipNxCache: boolean;
}

/**
* Provides data for the "Projects" tree view
*/
Expand All @@ -42,6 +46,7 @@ export class NxProjectTreeProvider extends AbstractTreeProvider<NxTreeItem> {
['revealInExplorer', this.revealInExplorer],
['runTask', this.runTask],
['refreshNxProjectsTree', this.refreshNxProjectsTree],
['runTaskSkipNxCache', this.runTaskSkipNxCache],
] as const
).forEach(([commandSuffix, callback]) => {
context.subscriptions.push(
Expand Down Expand Up @@ -90,7 +95,10 @@ export class NxProjectTreeProvider extends AbstractTreeProvider<NxTreeItem> {
return config === 'tree';
}

private async runTask(selection: NxTreeItem) {
private async runTask(
selection: NxTreeItem,
optionalFlags?: NxOptionalFlags
) {
const viewItem = selection.item;
if (
viewItem.contextValue === 'project' ||
Expand All @@ -107,13 +115,21 @@ export class NxProjectTreeProvider extends AbstractTreeProvider<NxTreeItem> {
flags.push(`--configuration=${target.configuration}`);
}

if (optionalFlags?.skipNxCache) {
flags.push('--skip-nx-cache');
}

this.cliTaskProvider.executeTask({
command: target.name,
positional: project,
flags,
});
}

private async runTaskSkipNxCache(selection: NxTreeItem) {
this.runTask(selection, { skipNxCache: true });
}

private async revealInExplorer(selection: NxTreeItem) {
if (selection.resourceUri) {
commands.executeCommand('revealInExplorer', selection.resourceUri);
Expand Down

0 comments on commit 3216ffd

Please sign in to comment.