Skip to content

Commit

Permalink
adding remove, version checks, removing for angular cli projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackDeRose committed Apr 10, 2022
1 parent c591644 commit e89a9e4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 45 deletions.
10 changes: 5 additions & 5 deletions apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions libs/vscode/nx-workspace/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
109 changes: 69 additions & 40 deletions libs/vscode/tasks/src/lib/cli-task-commands.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e89a9e4

Please sign in to comment.