Skip to content

Commit

Permalink
feat(core): add deprecation wrapper for workspace-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 19, 2023
1 parent ecd2245 commit 1804f32
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 124 deletions.
40 changes: 38 additions & 2 deletions docs/generated/cli/workspace-generator.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: 'workspace-generator - CLI command'
description: 'Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators'
description: 'Runs a workspace generator from the tools/generators directory'
---

# workspace-generator

**Deprecated:** Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators
**Deprecated:** Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators

Runs a workspace generator from the tools/generators directory

## Usage

Expand All @@ -17,12 +19,46 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`

## Options

### dryRun

Type: `boolean`

Default: `false`

Preview the changes without updating files

### generator

Type: `string`

Name of the generator (e.g., @nrwl/js:library, library)

### help

Type: `boolean`

Show help

### interactive

Type: `boolean`

Default: `true`

When false disables interactive input prompts for options

### quiet

Type: `boolean`

Hides logs from tree operations (e.g. `CREATE package.json`)

### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

### version

Type: `boolean`
Expand Down
40 changes: 38 additions & 2 deletions docs/generated/packages/nx/documents/workspace-generator.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: 'workspace-generator - CLI command'
description: 'Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators'
description: 'Runs a workspace generator from the tools/generators directory'
---

# workspace-generator

**Deprecated:** Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators
**Deprecated:** Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators

Runs a workspace generator from the tools/generators directory

## Usage

Expand All @@ -17,12 +19,46 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`

## Options

### dryRun

Type: `boolean`

Default: `false`

Preview the changes without updating files

### generator

Type: `string`

Name of the generator (e.g., @nrwl/js:library, library)

### help

Type: `boolean`

Show help

### interactive

Type: `boolean`

Default: `true`

When false disables interactive input prompts for options

### quiet

Type: `boolean`

Hides logs from tree operations (e.g. `CREATE package.json`)

### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

### version

Type: `boolean`
Expand Down
25 changes: 22 additions & 3 deletions e2e/nx-plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ describe('Nx Plugin', () => {
expect(results).not.toContain(goodMigration);
});

/**
* @todo(@AgentEnder): reenable after figuring out @swc-node
*/
describe('local plugins', () => {
let plugin: string;
beforeEach(() => {
Expand Down Expand Up @@ -368,6 +365,28 @@ describe('Nx Plugin', () => {
});
});

describe('workspace-generator', () => {
let custom: string;

it('should work with generate wrapper', () => {
custom = uniq('custom');
const project = uniq('generated-project');
runCLI(`g @nrwl/nx-plugin:plugin workspace-plugin --no-interactive`);
runCLI(
`g @nrwl/nx-plugin:generator ${custom} --project workspace-plugin --no-interactive`
);
runCLI(
`workspace-generator ${custom} --name ${project} --no-interactive`
);
expect(() => {
checkFilesExist(
`libs/${project}/src/index.ts`,
`libs/${project}/project.json`
);
});
});
});

describe('--directory', () => {
it('should create a plugin in the specified directory', () => {
const plugin = uniq('plugin');
Expand Down

This file was deleted.

This file was deleted.

19 changes: 11 additions & 8 deletions packages/nx/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,17 @@ export const commandsObject = yargs
process.exit(0);
},
})

/**
* @deprecated(v17): Remove `workspace-generator in v17. Use local plugins.
*/
.command({
command: 'workspace-generator [name]',
describe:
describe: 'Runs a workspace generator from the tools/generators directory',
deprecated:
'Use a local plugin instead. See: https://nx.dev/deprecated/workspace-generators',
deprecated: true,
aliases: ['workspace-schematic [name]'],
builder: async (yargs) =>
linkToNxDevAndExamples(yargs, 'workspace-generator'),
linkToNxDevAndExamples(withGenerateOptions(yargs), 'workspace-generator'),
handler: workspaceGeneratorHandler,
})
.command({
Expand Down Expand Up @@ -825,10 +827,11 @@ function withRunOneOptions(yargs: yargs.Argv) {
}
}

async function workspaceGeneratorHandler() {
await (
await import('./workspace-generators')
).workspaceGenerators(process.argv.slice(3));
/**
* @deprecated(v17): Remove `workspace-generator in v17. Use local plugins.
*/
async function workspaceGeneratorHandler(args: yargs.Arguments) {
await (await import('./workspace-generators')).workspaceGenerators(args);
process.exit(0);
}

Expand Down
41 changes: 29 additions & 12 deletions packages/nx/src/command-line/workspace-generators.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import yargs = require('yargs');
import { readNxJson } from '../config/configuration';
import { NxJsonConfiguration } from '../devkit-exports';
import { NX_PREFIX } from '../utils/logger';
import { output } from '../utils/output';

export async function workspaceGenerators(args: string[]) {
const bodyLines: string[] = [
'Instead, Nx now supports executing generators or executors from ',
'local plugins. To run a generator from a local plugin, ',
'use `nx generate` like you would with any other generator.',
'',
'For more information, see: https://nx.dev/deprecated/workspace-generators',
];
output.error({
/**
* Wraps `workspace-generator` to invoke `generate`.
*
* @deprecated(v17): Remove `workspace-generator in v17. Use local plugins.
*/
export async function workspaceGenerators(args: yargs.Arguments) {
const generator = process.argv.slice(3);

output.warn({
title: `${NX_PREFIX} Workspace Generators are no longer supported`,
bodyLines,
bodyLines: [
'Instead, Nx now supports executing generators or executors from ',
'local plugins. To run a generator from a local plugin, ',
'use `nx generate` like you would with any other generator.',
'',
'For more information, see: https://nx.dev/deprecated/workspace-generators',
],
});
// In case users have scripted around workspace-generator, this will ensure commands fail :)
process.exit(1);

const nxJson: NxJsonConfiguration = readNxJson();
const collection = nxJson.npmScope
? `@${nxJson.npmScope}/workspace-plugin`
: 'workspace-plugin';

args._ = args._.slice(1);
args.generator = `${collection}:${generator}`;

return (await import('./generate')).generate(process.cwd(), args);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Schema } from './schema';
import {
Tree,
stripIndents,
} from '@nx/devkit';
import { Tree, stripIndents } from '@nx/devkit';

export default async function (host: Tree, schema: Schema) {
const message = stripIndents`Workspace Generators are no longer supported. Instead,
Expand Down

This file was deleted.

Loading

0 comments on commit 1804f32

Please sign in to comment.