From e89a9e42e3f15c1ba39432d4fdf52a2aa1989d75 Mon Sep 17 00:00:00 2001 From: Zack DeRose Date: Sun, 10 Apr 2022 14:50:50 -0700 Subject: [PATCH] adding remove, version checks, removing for angular cli projects --- apps/vscode/src/package.json | 10 +- libs/vscode/nx-workspace/src/index.ts | 1 + .../vscode/tasks/src/lib/cli-task-commands.ts | 109 +++++++++++------- 3 files changed, 75 insertions(+), 45 deletions(-) diff --git a/apps/vscode/src/package.json b/apps/vscode/src/package.json index ea95159e70..1d81572815 100644 --- a/apps/vscode/src/package.json +++ b/apps/vscode/src/package.json @@ -80,8 +80,8 @@ "group": "2_workspace" }, { - "when": "isAngularWorkspace && config.nxConsole.enableGenerateFromContextMenu", - "command": "ng.move.fileexplorer", + "when": "isNxWorkspace && config.nxConsole.enableGenerateFromContextMenu", + "command": "nx.remove.fileexplorer", "group": "2_workspace" }, { @@ -579,9 +579,9 @@ "command": "nx.move.fileexplorer" }, { - "category": "ng", - "title": "Move Nx Project...", - "command": "ng.move.fileexplorer" + "category": "Nx", + "title": "Remove Nx Project...", + "command": "nx.move.fileexplorer" }, { "category": "Nx", diff --git a/libs/vscode/nx-workspace/src/index.ts b/libs/vscode/nx-workspace/src/index.ts index e69a7e408b..ba0baca1d9 100644 --- a/libs/vscode/nx-workspace/src/index.ts +++ b/libs/vscode/nx-workspace/src/index.ts @@ -4,3 +4,4 @@ export * from './lib/workspace-codelens-provider'; export * from './lib/verify-workspace'; export * from './lib/get-nx-config'; export * from './lib/get-nx-workspace-config'; +export * from './lib/nx-version'; diff --git a/libs/vscode/tasks/src/lib/cli-task-commands.ts b/libs/vscode/tasks/src/lib/cli-task-commands.ts index 0f4fb4d5c0..3fd812b583 100644 --- a/libs/vscode/tasks/src/lib/cli-task-commands.ts +++ b/libs/vscode/tasks/src/lib/cli-task-commands.ts @@ -1,23 +1,14 @@ -import { - commands, - ExtensionContext, - window, - Uri, - Task, - TaskScope, - tasks, -} from 'vscode'; - -import { verifyWorkspace } from '@nx-console/vscode/nx-workspace'; +import { commands, ExtensionContext, window, Uri } from 'vscode'; + +import { nxVersion, verifyWorkspace } from '@nx-console/vscode/nx-workspace'; import { verifyBuilderDefinition } from '@nx-console/vscode/verify'; import { RunTargetTreeItem } from '@nx-console/vscode/nx-run-target-view'; import { CliTaskProvider } from './cli-task-provider'; import { CliTaskQuickPickItem } from './cli-task-quick-pick-item'; import { selectFlags } from './select-flags'; import { GeneratorType, Option, OptionType } from '@nx-console/schema'; -import { getWorkspacePath, WorkspaceJsonConfiguration } from '@nrwl/devkit'; +import { WorkspaceJsonConfiguration } from '@nrwl/devkit'; import { selectGenerator } from './select-generator'; -import { exec } from 'child_process'; import { getGenerators } from '@nx-console/server'; const CLI_COMMAND_LIST = [ @@ -77,34 +68,72 @@ export function registerCliTaskCommands( selectCliCommandAndPromptForFlags('run', await getCliProjectFromUri(uri)) ); - commands.registerCommand(`${cli}.move.fileexplorer`, async (uri: Uri) => { - /** - * Bit of a hack - always runs angular/move if it is installed. - * - * As of the date of implementation, no issues with running this angular generator - * on non-angular projects. BUT THIS MIGHT CHANGE IN THE FUTURE. - * - * Also, future may hold other framework specific move/remove generators - this - * solution won't work when that happens. - */ - const getCorrectMoveGenerator = async () => { - const workspacePath = cliTaskProvider.getWorkspacePath(); - const generators = await getGenerators(workspacePath); - return generators.find( - (generator) => generator.name === '@nrwl/angular:move' - ) - ? '@nrwl/angular:move' - : '@nrwl/workspace:move'; - }; - const generator = await getCorrectMoveGenerator(); - selectCliCommandAndShowUi( - 'generate', - context.extensionPath, - uri, - GeneratorType.Other, - generator + /** + * move and remove were release in patch 8.11 + */ + const version = nxVersion(); + if (version && version >= 8) { + commands.registerCommand(`${cli}.move.fileexplorer`, async (uri: Uri) => { + /** + * Bit of a hack - always runs angular/move if it is installed. + * + * As of the date of implementation, no issues with running this angular generator + * on non-angular projects. BUT THIS MIGHT CHANGE IN THE FUTURE. + * + * Also, future may hold other framework specific move/remove generators - this + * solution won't work when that happens. + */ + const getCorrectMoveGenerator = async () => { + const workspacePath = cliTaskProvider.getWorkspacePath(); + const generators = await getGenerators(workspacePath); + return generators.find( + (generator) => generator.name === '@nrwl/angular:move' + ) + ? '@nrwl/angular:move' + : '@nrwl/workspace:move'; + }; + const generator = await getCorrectMoveGenerator(); + selectCliCommandAndShowUi( + 'generate', + context.extensionPath, + uri, + GeneratorType.Other, + generator + ); + }); + + commands.registerCommand( + `${cli}.remove.fileexplorer`, + async (uri: Uri) => { + /** + * Bit of a hack - always runs angular/remove if it is installed. + * + * As of the date of implementation, no issues with running this angular generator + * on non-angular projects. BUT THIS MIGHT CHANGE IN THE FUTURE. + * + * Also, future may hold other framework specific move/remove generators - this + * solution won't work when that happens. + */ + const getCorrectRemoveGenerator = async () => { + const workspacePath = cliTaskProvider.getWorkspacePath(); + const generators = await getGenerators(workspacePath); + return generators.find( + (generator) => generator.name === '@nrwl/angular:remove' + ) + ? '@nrwl/angular:remove' + : '@nrwl/workspace:remove'; + }; + const generator = await getCorrectRemoveGenerator(); + selectCliCommandAndShowUi( + 'generate', + context.extensionPath, + uri, + GeneratorType.Other, + generator + ); + } ); - }); + } commands.registerCommand(`${cli}.generate`, () => selectGeneratorAndPromptForFlags()