diff --git a/apps/dep-graph-client/src/graphs/medium.ts b/apps/dep-graph-client/src/graphs/medium.ts index b7c88ef147..903dee8fc4 100644 --- a/apps/dep-graph-client/src/graphs/medium.ts +++ b/apps/dep-graph-client/src/graphs/medium.ts @@ -14630,7 +14630,7 @@ export const mediumGraph = { }, { file: - 'apps/nx-docs-site/src/assets/content/shared/tools-workspace-schematics.md', + 'apps/nx-docs-site/src/assets/content/shared/tools-workspace-generators.md', hash: '36a8e3fdd9166bebbc14220e92feb4e32f0d2f96', ext: '.md', }, diff --git a/docs/angular/api-workspace/schematics/workspace-schematic.md b/docs/angular/api-workspace/schematics/workspace-generator.md similarity index 53% rename from docs/angular/api-workspace/schematics/workspace-schematic.md rename to docs/angular/api-workspace/schematics/workspace-generator.md index 48d2b6607b..0552a6aaed 100644 --- a/docs/angular/api-workspace/schematics/workspace-schematic.md +++ b/docs/angular/api-workspace/schematics/workspace-generator.md @@ -1,25 +1,29 @@ -# workspace-schematic +# workspace-generator -Generates a workspace schematic +Generates a workspace generator ## Usage ```bash -nx generate workspace-schematic ... +nx generate workspace-generator ... ``` -By default, Nx will search for `workspace-schematic` in the default collection provisioned in `angular.json`. +```bash +nx g workspace-schematic ... # same +``` + +By default, Nx will search for `workspace-generator` in the default collection provisioned in `angular.json`. You can specify the collection explicitly as follows: ```bash -nx g @nrwl/workspace:workspace-schematic ... +nx g @nrwl/workspace:workspace-generator ... ``` Show what will be generated without writing to disk: ```bash -nx g workspace-schematic ... --dry-run +nx g workspace-generator ... --dry-run ``` ## Options diff --git a/docs/angular/cli/workspace-schematic.md b/docs/angular/cli/workspace-generator.md similarity index 51% rename from docs/angular/cli/workspace-schematic.md rename to docs/angular/cli/workspace-generator.md index 1935090762..dca864f7aa 100644 --- a/docs/angular/cli/workspace-schematic.md +++ b/docs/angular/cli/workspace-generator.md @@ -1,11 +1,11 @@ -# workspace-schematic +# workspace-generator -Runs a workspace schematic from the tools/schematics directory +Runs a workspace generator from the tools/generators directory ## Usage ```bash -nx workspace-schematic +nx workspace-generator ``` Install `nx` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. @@ -16,13 +16,13 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npm run Show help -### list-schematics +### list-generators -List the available workspace-schematics +List the available workspace-generators ### name -The name of your schematic` +The name of your generator` ### version diff --git a/docs/map.json b/docs/map.json index 38cc9cc447..89c9938a54 100644 --- a/docs/map.json +++ b/docs/map.json @@ -236,9 +236,9 @@ "file": "angular/cli/workspace-lint" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "angular/cli/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "angular/cli/workspace-generator" } ] }, @@ -287,9 +287,9 @@ "file": "angular/api-workspace/schematics/run-commands" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "angular/api-workspace/schematics/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "angular/api-workspace/schematics/workspace-generator" } ] }, @@ -941,8 +941,8 @@ }, { "name": "Workspace Schematics", - "id": "workspace-schematics", - "file": "shared/tools-workspace-schematics" + "id": "workspace-generators", + "file": "shared/tools-workspace-generators" } ] }, @@ -1329,9 +1329,9 @@ "file": "react/cli/workspace-lint" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "react/cli/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "react/cli/workspace-generator" } ] }, @@ -1380,9 +1380,9 @@ "file": "react/api-workspace/schematics/run-commands" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "react/api-workspace/schematics/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "react/api-workspace/schematics/workspace-generator" } ] }, @@ -2034,8 +2034,8 @@ }, { "name": "Workspace Schematics", - "id": "workspace-schematics", - "file": "shared/tools-workspace-schematics" + "id": "workspace-generators", + "file": "shared/tools-workspace-generators" } ] }, @@ -2375,9 +2375,9 @@ "file": "node/cli/workspace-lint" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "node/cli/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "node/cli/workspace-generator" } ] }, @@ -2426,9 +2426,9 @@ "file": "node/api-workspace/schematics/run-commands" }, { - "name": "workspace-schematic", - "id": "workspace-schematic", - "file": "node/api-workspace/schematics/workspace-schematic" + "name": "workspace-generator", + "id": "workspace-generator", + "file": "node/api-workspace/schematics/workspace-generator" } ] }, @@ -3074,8 +3074,8 @@ }, { "name": "Workspace Schematics", - "id": "workspace-schematics", - "file": "shared/tools-workspace-schematics" + "id": "workspace-generators", + "file": "shared/tools-workspace-generators" } ] }, diff --git a/docs/react/api-workspace/schematics/workspace-schematic.md b/docs/node/api-workspace/schematics/workspace-generator.md similarity index 53% rename from docs/react/api-workspace/schematics/workspace-schematic.md rename to docs/node/api-workspace/schematics/workspace-generator.md index d90b6755c4..dc7fd9b015 100644 --- a/docs/react/api-workspace/schematics/workspace-schematic.md +++ b/docs/node/api-workspace/schematics/workspace-generator.md @@ -1,25 +1,29 @@ -# workspace-schematic +# workspace-generator -Generates a workspace schematic +Generates a workspace generator ## Usage ```bash -nx generate workspace-schematic ... +nx generate workspace-generator ... ``` -By default, Nx will search for `workspace-schematic` in the default collection provisioned in `workspace.json`. +```bash +nx g workspace-schematic ... # same +``` + +By default, Nx will search for `workspace-generator` in the default collection provisioned in `workspace.json`. You can specify the collection explicitly as follows: ```bash -nx g @nrwl/workspace:workspace-schematic ... +nx g @nrwl/workspace:workspace-generator ... ``` Show what will be generated without writing to disk: ```bash -nx g workspace-schematic ... --dry-run +nx g workspace-generator ... --dry-run ``` ## Options diff --git a/docs/react/cli/workspace-schematic.md b/docs/node/cli/workspace-generator.md similarity index 51% rename from docs/react/cli/workspace-schematic.md rename to docs/node/cli/workspace-generator.md index 1935090762..dca864f7aa 100644 --- a/docs/react/cli/workspace-schematic.md +++ b/docs/node/cli/workspace-generator.md @@ -1,11 +1,11 @@ -# workspace-schematic +# workspace-generator -Runs a workspace schematic from the tools/schematics directory +Runs a workspace generator from the tools/generators directory ## Usage ```bash -nx workspace-schematic +nx workspace-generator ``` Install `nx` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. @@ -16,13 +16,13 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npm run Show help -### list-schematics +### list-generators -List the available workspace-schematics +List the available workspace-generators ### name -The name of your schematic` +The name of your generator` ### version diff --git a/docs/node/api-workspace/schematics/workspace-schematic.md b/docs/react/api-workspace/schematics/workspace-generator.md similarity index 53% rename from docs/node/api-workspace/schematics/workspace-schematic.md rename to docs/react/api-workspace/schematics/workspace-generator.md index d90b6755c4..dc7fd9b015 100644 --- a/docs/node/api-workspace/schematics/workspace-schematic.md +++ b/docs/react/api-workspace/schematics/workspace-generator.md @@ -1,25 +1,29 @@ -# workspace-schematic +# workspace-generator -Generates a workspace schematic +Generates a workspace generator ## Usage ```bash -nx generate workspace-schematic ... +nx generate workspace-generator ... ``` -By default, Nx will search for `workspace-schematic` in the default collection provisioned in `workspace.json`. +```bash +nx g workspace-schematic ... # same +``` + +By default, Nx will search for `workspace-generator` in the default collection provisioned in `workspace.json`. You can specify the collection explicitly as follows: ```bash -nx g @nrwl/workspace:workspace-schematic ... +nx g @nrwl/workspace:workspace-generator ... ``` Show what will be generated without writing to disk: ```bash -nx g workspace-schematic ... --dry-run +nx g workspace-generator ... --dry-run ``` ## Options diff --git a/docs/node/cli/workspace-schematic.md b/docs/react/cli/workspace-generator.md similarity index 51% rename from docs/node/cli/workspace-schematic.md rename to docs/react/cli/workspace-generator.md index 1935090762..dca864f7aa 100644 --- a/docs/node/cli/workspace-schematic.md +++ b/docs/react/cli/workspace-generator.md @@ -1,11 +1,11 @@ -# workspace-schematic +# workspace-generator -Runs a workspace schematic from the tools/schematics directory +Runs a workspace generator from the tools/generators directory ## Usage ```bash -nx workspace-schematic +nx workspace-generator ``` Install `nx` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. @@ -16,13 +16,13 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npm run Show help -### list-schematics +### list-generators -List the available workspace-schematics +List the available workspace-generators ### name -The name of your schematic` +The name of your generator` ### version diff --git a/docs/shared/tools-workspace-schematics.md b/docs/shared/tools-workspace-generators.md similarity index 100% rename from docs/shared/tools-workspace-schematics.md rename to docs/shared/tools-workspace-generators.md diff --git a/e2e/angular/src/ng-add.test.ts b/e2e/angular/src/ng-add.test.ts index d7feb09638..a8ecabf026 100644 --- a/e2e/angular/src/ng-add.test.ts +++ b/e2e/angular/src/ng-add.test.ts @@ -88,7 +88,7 @@ forEachCli('angular', () => { 'update:check': 'ng update', postinstall: 'node ./decorate-angular-cli.js', 'dep-graph': 'nx dep-graph', - 'workspace-schematic': 'nx workspace-schematic', + 'workspace-generator': 'nx workspace-generator', help: 'nx help', }); expect( diff --git a/e2e/cli/src/cli.test.ts b/e2e/cli/src/cli.test.ts index 4ed922408c..45a97a71ac 100644 --- a/e2e/cli/src/cli.test.ts +++ b/e2e/cli/src/cli.test.ts @@ -16,6 +16,7 @@ forEachCli('nx', () => { describe('Help', () => { it('should show help', async () => { newProject(); + // sss const myapp = uniq('myapp'); runCLI(`generate @nrwl/web:app ${myapp}`); diff --git a/e2e/workspace/src/workspace-aux-commands.test.ts b/e2e/workspace/src/workspace-aux-commands.test.ts index 699a166163..7a4c9e116b 100644 --- a/e2e/workspace/src/workspace-aux-commands.test.ts +++ b/e2e/workspace/src/workspace-aux-commands.test.ts @@ -215,27 +215,27 @@ forEachCli((cli) => { }); }); - describe('workspace-schematic', () => { + describe('workspace-generator', () => { let custom: string; let failing: string; beforeEach(() => { custom = uniq('custom'); failing = uniq('custom-failing'); - runCLI(`g workspace-schematic ${custom} --no-interactive`); - runCLI(`g workspace-schematic ${failing} --no-interactive`); + runCLI(`g workspace-generator ${custom} --no-interactive`); + runCLI(`g workspace-generator ${failing} --no-interactive`); checkFilesExist( - `tools/schematics/${custom}/index.ts`, - `tools/schematics/${custom}/schema.json` + `tools/generators/${custom}/index.ts`, + `tools/generators/${custom}/schema.json` ); checkFilesExist( - `tools/schematics/${failing}/index.ts`, - `tools/schematics/${failing}/schema.json` + `tools/generators/${failing}/index.ts`, + `tools/generators/${failing}/schema.json` ); }); - it('should compile only schematic files with dependencies', () => { + it('should compile only generator files with dependencies', () => { const workspace = uniq('workspace'); updateFile( @@ -251,12 +251,12 @@ forEachCli((cli) => { ` ); updateFile( - `tools/schematics/utils.ts`, + `tools/generators/utils.ts`, ` export const noop = ()=>{} ` ); - updateFile(`tools/schematics/${custom}/index.ts`, (content) => { + updateFile(`tools/generators/${custom}/index.ts`, (content) => { return ` import { log } from '../../utils/logger'; \n ${content} @@ -264,13 +264,13 @@ forEachCli((cli) => { }); runCommand( - `nx workspace-schematic ${custom} ${workspace} --no-interactive -d` + `nx workspace-generator ${custom} ${workspace} --no-interactive -d` ); expect(() => checkFilesExist( - `dist/out-tsc/tools/schematics/${custom}/index.js`, - `dist/out-tsc/tools/schematics/utils.js`, + `dist/out-tsc/tools/generators/${custom}/index.js`, + `dist/out-tsc/tools/generators/utils.js`, `dist/out-tsc/tools/utils/logger.js` ) ).not.toThrow(); @@ -279,8 +279,8 @@ forEachCli((cli) => { ).toThrow(); }); - it('should support workspace-specific schematics', async () => { - const json = readJson(`tools/schematics/${custom}/schema.json`); + it('should support workspace-specific generators', async () => { + const json = readJson(`tools/generators/${custom}/schema.json`); json.properties['directory'] = { type: 'string', description: 'lib directory', @@ -290,13 +290,13 @@ forEachCli((cli) => { description: 'skip changes to tsconfig', }; updateFile( - `tools/schematics/${custom}/schema.json`, + `tools/generators/${custom}/schema.json`, JSON.stringify(json) ); - const indexFile = readFile(`tools/schematics/${custom}/index.ts`); + const indexFile = readFile(`tools/generators/${custom}/index.ts`); updateFile( - `tools/schematics/${custom}/index.ts`, + `tools/generators/${custom}/index.ts`, indexFile.replace( 'name: schema.name', 'name: schema.name, directory: schema.directory, skipTsConfig: schema.skipTsConfig' @@ -305,29 +305,29 @@ forEachCli((cli) => { const workspace = uniq('workspace'); const dryRunOutput = runCLI( - `workspace-schematic ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d` + `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d` ); expect(exists(`libs/dir/${workspace}/src/index.ts`)).toEqual(false); expect(dryRunOutput).toContain(`UPDATE ${workspaceConfigName()}`); expect(dryRunOutput).toContain('UPDATE nx.json'); const output = runCLI( - `workspace-schematic ${custom} ${workspace} --no-interactive --directory=dir` + `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir` ); checkFilesExist(`libs/dir/${workspace}/src/index.ts`); expect(output).toContain(`UPDATE ${workspaceConfigName()}`); expect(output).toContain('UPDATE nx.json'); - const jsonFailing = readJson(`tools/schematics/${failing}/schema.json`); + const jsonFailing = readJson(`tools/generators/${failing}/schema.json`); jsonFailing.properties = {}; jsonFailing.required = []; updateFile( - `tools/schematics/${failing}/schema.json`, + `tools/generators/${failing}/schema.json`, JSON.stringify(jsonFailing) ); updateFile( - `tools/schematics/${failing}/index.ts`, + `tools/generators/${failing}/index.ts`, ` export default function() { throw new Error(); @@ -336,15 +336,13 @@ forEachCli((cli) => { ); try { - await runCLI(`workspace-schematic ${failing} --no-interactive`); - fail(`Should exit 1 for a workspace-schematic that throws an error`); + await runCLI(`workspace-generator ${failing} --no-interactive`); + fail(`Should exit 1 for a workspace-generator that throws an error`); } catch (e) {} - const listSchematicsOutput = runCLI( - 'workspace-schematic --list-schematics' - ); - expect(listSchematicsOutput).toContain(custom); - expect(listSchematicsOutput).toContain(failing); + const listOutput = runCLI('workspace-generator --list-generators'); + expect(listOutput).toContain(custom); + expect(listOutput).toContain(failing); }, 1000000); }); diff --git a/package.json b/package.json index f586c4cbb3..a055398dff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nrwl/nx-source", - "version": "11.0.0-beta.2", + "version": "11.0.0-beta.4", "description": "Extensible Dev Tools for Monorepos", "homepage": "https://nx.dev", "main": "index.js", diff --git a/packages/cli/lib/init-local.ts b/packages/cli/lib/init-local.ts index e34a2d05ba..69544f35a1 100644 --- a/packages/cli/lib/init-local.ts +++ b/packages/cli/lib/init-local.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as fs from 'fs'; import { Workspace } from './workspace'; import { parseRunOneOptions } from './parse-run-one-options'; -import { useNxToRunNxBuilderOrSchematic } from './use-nx-to-run-nx-builder-or-schematic'; +import { useNxToRunNxBuilderOrGenerator } from './use-nx-to-run-nx-builder-or-generator'; /** * Nx is being run inside a workspace. @@ -27,7 +27,7 @@ export function initLocal(workspace: Workspace) { } else { // not using the tasks runner if (runOpts === false || process.env.NX_SKIP_TASKS_RUNNER) { - loadCli(workspace, useNxToRunNxBuilderOrSchematic()); + loadCli(workspace, useNxToRunNxBuilderOrGenerator()); } else { require('@nrwl/workspace' + '/src/command-line/run-one').runOne(runOpts); } diff --git a/packages/cli/lib/use-nx-to-run-nx-builder-or-schematic.ts b/packages/cli/lib/use-nx-to-run-nx-builder-or-generator.ts similarity index 76% rename from packages/cli/lib/use-nx-to-run-nx-builder-or-schematic.ts rename to packages/cli/lib/use-nx-to-run-nx-builder-or-generator.ts index b6d3daade2..437f7b4d69 100644 --- a/packages/cli/lib/use-nx-to-run-nx-builder-or-schematic.ts +++ b/packages/cli/lib/use-nx-to-run-nx-builder-or-generator.ts @@ -8,12 +8,12 @@ import { } from '@nrwl/tao/src/shared/workspace'; const ws = new Workspaces(); -export function useNxToRunNxBuilderOrSchematic() { +export function useNxToRunNxBuilderOrGenerator() { try { const dir = findWorkspaceRoot(__dirname).dir; const args = process.argv.slice(2); const wd = ws.readWorkspaceConfiguration(dir); - return isNxBuilder(dir, args, wd) || isNxSchematic(dir, args, wd); + return isNxBuilder(dir, args, wd) || isNxGenerator(dir, args, wd); } catch (e) { return false; } @@ -33,17 +33,17 @@ function isNxBuilder(dir: string, args: string[], wd: WorkspaceDefinition) { } } -function isNxSchematic(dir: string, args: string[], wd: WorkspaceDefinition) { +function isNxGenerator(dir: string, args: string[], wd: WorkspaceDefinition) { try { if (args[0] != 'g' && args[0] != 'generate') return false; const defaultCollection = wd.cli ? wd.cli.defaultCollection : null; - let [collectionName, schematicName] = args[1].split(':'); - if (!schematicName) { - schematicName = collectionName; + let [collectionName, generatorName] = args[1].split(':'); + if (!generatorName) { + generatorName = collectionName; collectionName = defaultCollection; } - return ws.isNxSchematic(collectionName, schematicName); + return ws.isNxGenerator(collectionName, generatorName); } catch (e) { return false; } diff --git a/packages/tao/src/commands/generate.ts b/packages/tao/src/commands/generate.ts index 65580bbdd5..a3a259720e 100644 --- a/packages/tao/src/commands/generate.ts +++ b/packages/tao/src/commands/generate.ts @@ -1,13 +1,13 @@ import * as minimist from 'minimist'; import { getLogger } from '../shared/logger'; import { - combineOptionsForSchematic, + combineOptionsForGenerator, convertToCamelCase, handleErrors, Options, Schema, } from '../shared/params'; -import { commandName, printHelp } from '../shared/print-help'; +import { printHelp } from '../shared/print-help'; import { WorkspaceDefinition, Workspaces } from '../shared/workspace'; import { statSync, unlinkSync, writeFileSync } from 'fs'; import { mkdirpSync, rmdirSync } from 'fs-extra'; @@ -18,8 +18,8 @@ const chalk = require('chalk'); export interface GenerateOptions { collectionName: string; - schematicName: string; - schematicOptions: Options; + generatorName: string; + generatorOptions: Options; help: boolean; debug: boolean; dryRun: boolean; @@ -30,7 +30,7 @@ export interface GenerateOptions { function throwInvalidInvocation() { throw new Error( - `Specify the schematic name (e.g., ${commandName} generate collection-name:schematic-name)` + `Specify the generator name (e.g., nx generate @nrwl/workspace:library)` ); } @@ -39,7 +39,7 @@ function parseGenerateOpts( mode: 'generate' | 'new', defaultCollection: string | null ): GenerateOptions { - const schematicOptions = convertToCamelCase( + const generatorOptions = convertToCamelCase( minimist(args, { boolean: ['help', 'dryRun', 'debug', 'force', 'interactive'], alias: { @@ -55,24 +55,24 @@ function parseGenerateOpts( ); let collectionName: string | null = null; - let schematicName: string | null = null; + let generatorName: string | null = null; if (mode === 'generate') { if ( - !schematicOptions['_'] || - (schematicOptions['_'] as string[]).length === 0 + !generatorOptions['_'] || + (generatorOptions['_'] as string[]).length === 0 ) { throwInvalidInvocation(); } - [collectionName, schematicName] = (schematicOptions['_'] as string[]) + [collectionName, generatorName] = (generatorOptions['_'] as string[]) .shift() .split(':'); - if (!schematicName) { - schematicName = collectionName; + if (!generatorName) { + generatorName = collectionName; collectionName = defaultCollection; } } else { - collectionName = schematicOptions.collection as string; - schematicName = ''; + collectionName = generatorOptions.collection as string; + generatorName = ''; } if (!collectionName) { @@ -81,24 +81,24 @@ function parseGenerateOpts( const res = { collectionName, - schematicName, - schematicOptions, - help: schematicOptions.help as boolean, - debug: schematicOptions.debug as boolean, - dryRun: schematicOptions.dryRun as boolean, - force: schematicOptions.force as boolean, - interactive: schematicOptions.interactive as boolean, - defaults: schematicOptions.defaults as boolean, + generatorName, + generatorOptions, + help: generatorOptions.help as boolean, + debug: generatorOptions.debug as boolean, + dryRun: generatorOptions.dryRun as boolean, + force: generatorOptions.force as boolean, + interactive: generatorOptions.interactive as boolean, + defaults: generatorOptions.defaults as boolean, }; - delete schematicOptions.debug; - delete schematicOptions.d; - delete schematicOptions.dryRun; - delete schematicOptions.force; - delete schematicOptions.interactive; - delete schematicOptions.defaults; - delete schematicOptions.help; - delete schematicOptions['--']; + delete generatorOptions.debug; + delete generatorOptions.d; + delete generatorOptions.dryRun; + delete generatorOptions.force; + delete generatorOptions.interactive; + delete generatorOptions.defaults; + delete generatorOptions.help; + delete generatorOptions['--']; return res; } @@ -109,7 +109,7 @@ export function printGenHelp( logger: Console ) { printHelp( - `${commandName} generate ${opts.collectionName}:${opts.schematicName}`, + `nx generate ${opts.collectionName}:${opts.generatorName}`, { ...schema, properties: { @@ -186,10 +186,10 @@ export async function generate( readDefaultCollection(workspaceDefinition) ); - if (ws.isNxSchematic(opts.collectionName, opts.schematicName)) { - const { schema, implementation } = ws.readSchematic( + if (ws.isNxGenerator(opts.collectionName, opts.generatorName)) { + const { schema, implementation } = ws.readGenerator( opts.collectionName, - opts.schematicName + opts.generatorName ); if (opts.help) { @@ -197,10 +197,10 @@ export async function generate( return 0; } - const combinedOpts = await combineOptionsForSchematic( - opts.schematicOptions, + const combinedOpts = await combineOptionsForGenerator( + opts.generatorOptions, opts.collectionName, - opts.schematicName, + opts.generatorName, workspaceDefinition, schema, opts.interactive diff --git a/packages/tao/src/commands/help.ts b/packages/tao/src/commands/help.ts index 8c3b358655..7f5c52d162 100644 --- a/packages/tao/src/commands/help.ts +++ b/packages/tao/src/commands/help.ts @@ -1,42 +1,35 @@ import { tags, terminal } from '@angular-devkit/core'; import { getLogger } from '../shared/logger'; -import { commandName, toolDescription } from '../shared/print-help'; export function help() { const logger = getLogger(true); logger.info(tags.stripIndent` - ${terminal.bold(toolDescription)} + ${terminal.bold('Nx - Extensible Dev Tools for Monorepos.')} ${terminal.bold('Create a new project.')} - ${commandName} new ${terminal.grey( - '[project-name] [--collection=schematic-collection] [options, ...]' - )} + nx new ${terminal.grey( + '[project-name] [--collection=collection] [options, ...]' + )} ${terminal.bold('Generate code.')} - ${commandName} generate ${terminal.grey( - '[schematic-collection:][schematic] [options, ...]' - )} - ${commandName} g ${terminal.grey( - '[schematic-collection:][schematic] [options, ...]' - )} + nx generate ${terminal.grey('[collection:][generator] [options, ...]')} + nx g ${terminal.grey('[collection:][generator] [options, ...]')} ${terminal.bold('Run target.')} - ${commandName} run ${terminal.grey( - '[project][:target][:configuration] [options, ...]' - )} - ${commandName} r ${terminal.grey( - '[project][:target][:configuration] [options, ...]' - )} + nx run ${terminal.grey( + '[project][:target][:configuration] [options, ...]' + )} + nx r ${terminal.grey('[project][:target][:configuration] [options, ...]')} You can also use the infix notation to run a target: - ${commandName} [target] [project] [options, ...] + nx [target] [project] [options, ...] ${terminal.bold('Migrate packages and create migrations.json.')} - ${commandName} migrate ${terminal.grey('[package-name]')} + nx migrate ${terminal.grey('[package-name]')} ${terminal.bold('Run migrations.')} - ${commandName} migrate ${terminal.grey('--run-migrations=[filename]')} + nx migrate ${terminal.grey('--run-migrations=[filename]')} `); return 0; diff --git a/packages/tao/src/commands/ngcli-adapter.ts b/packages/tao/src/commands/ngcli-adapter.ts index d0c2265bad..6fa86e8cb6 100644 --- a/packages/tao/src/commands/ngcli-adapter.ts +++ b/packages/tao/src/commands/ngcli-adapter.ts @@ -96,8 +96,8 @@ async function createWorkflow( registry: new schema.CoreSchemaRegistry(formats.standardFormats), resolvePaths: [process.cwd(), root], }); - const _params = opts.schematicOptions._; - delete opts.schematicOptions._; + const _params = opts.generatorOptions._; + delete opts.generatorOptions._; workflow.registry.addSmartDefaultProvider('argv', (schema: JsonObject) => { if ('index' in schema) { return _params[Number(schema['index'])]; @@ -272,25 +272,25 @@ async function runSchematic( } const defaults = - opts.schematicName === 'tao-new' || opts.schematicName === 'ng-new' + opts.generatorName === 'tao-new' || opts.generatorName === 'ng-new' ? {} : await getSchematicDefaults( root, opts.collectionName, - opts.schematicName + opts.generatorName ); const record = { loggingQueue: [] as string[], error: false }; workflow.reporter.subscribe(recorder || createRecorder(record, logger)); const schematicOptions = normalizeOptions( - opts.schematicOptions, + opts.generatorOptions, flattenedSchema ); if (schematicOptions['--'] && !allowAdditionalArgs) { schematicOptions['--'].forEach((unmatched) => { const message = - `Could not match option '${unmatched.name}' to the ${opts.collectionName}:${opts.schematicName} schema.` + + `Could not match option '${unmatched.name}' to the ${opts.collectionName}:${opts.generatorName} schema.` + (unmatched.possible.length > 0 ? ` Possible matches : ${unmatched.possible.join()}` : ''); @@ -303,7 +303,7 @@ async function runSchematic( await workflow .execute({ collection: opts.collectionName, - schematic: opts.schematicName, + schematic: opts.generatorName, options: { ...defaults, ...schematicOptions }, debug: opts.debug, logger, @@ -335,13 +335,13 @@ export async function generate( ); const workflow = await createWorkflow(fsHost, root, opts); const collection = getCollection(workflow, opts.collectionName); - const schematic = collection.createSchematic(opts.schematicName, true); + const schematic = collection.createSchematic(opts.generatorName, true); return ( await runSchematic( root, workflow, logger, - { ...opts, schematicName: schematic.description.name }, + { ...opts, generatorName: schematic.description.name }, schematic ) ).status; @@ -349,9 +349,9 @@ export async function generate( export function wrapAngularDevkitSchematic( collectionName: string, - schematicName: string + generatorName: string ) { - return (schematicOptions: { [k: string]: any }) => { + return (generatorOptions: { [k: string]: any }) => { return async (host: taoTree.Tree) => { const emptyLogger = { log: (e) => {}, @@ -394,19 +394,19 @@ export function wrapAngularDevkitSchematic( ); const options = { - schematicOptions: { ...schematicOptions, _: [] }, + generatorOptions: { ...generatorOptions, _: [] }, dryRun: true, interactive: false, help: false, debug: false, collectionName, - schematicName, + generatorName, force: false, defaults: false, }; const workflow = await createWorkflow(fsHost, host.root, options); const collection = getCollection(workflow, collectionName); - const schematic = collection.createSchematic(schematicName, true); + const schematic = collection.createSchematic(generatorName, true); const res = await runSchematic( host.root, workflow, @@ -437,7 +437,7 @@ export async function invokeNew( const workflow = await createWorkflow(fsHost, root, opts); const collection = getCollection(workflow, opts.collectionName); const schematic = collection.createSchematic( - opts.schematicOptions.cli === 'ng' ? 'ng-new' : 'tao-new', + opts.generatorOptions.cli === 'ng' ? 'ng-new' : 'tao-new', true ); const allowAdditionalArgs = true; // we can't yet know the schema to validate against @@ -446,7 +446,7 @@ export async function invokeNew( root, workflow, logger, - { ...opts, schematicName: schematic.description.name }, + { ...opts, generatorName: schematic.description.name }, schematic, allowAdditionalArgs ) diff --git a/packages/tao/src/commands/run.ts b/packages/tao/src/commands/run.ts index b1f97ba240..47226bb605 100644 --- a/packages/tao/src/commands/run.ts +++ b/packages/tao/src/commands/run.ts @@ -7,7 +7,7 @@ import { Options, Schema, } from '../shared/params'; -import { commandName, printHelp } from '../shared/print-help'; +import { printHelp } from '../shared/print-help'; import { TargetDefinition, WorkspaceDefinition, @@ -26,7 +26,7 @@ export interface RunOptions { function throwInvalidInvocation() { throw new Error( - `Specify the project name and the target (e.g., ${commandName} run proj:build)` + `Specify the project name and the target (e.g., nx run proj:build)` ); } @@ -86,11 +86,7 @@ export function printRunHelp( schema: Schema, logger: Console ) { - printHelp( - `${commandName} run ${opts.project}:${opts.target}`, - schema, - logger as any - ); + printHelp(`nx run ${opts.project}:${opts.target}`, schema, logger as any); } export function validateTargetAndConfiguration( diff --git a/packages/tao/src/shared/params.ts b/packages/tao/src/shared/params.ts index 30694a6e5d..ca854fd0d8 100644 --- a/packages/tao/src/shared/params.ts +++ b/packages/tao/src/shared/params.ts @@ -41,7 +41,7 @@ export async function handleErrors( return await fn(); } catch (err) { if (err.constructor.name === 'UnsuccessfulWorkflowExecution') { - logger.error('The Schematic workflow failed. See above.'); + logger.error('The generator workflow failed. See above.'); } else { logger.error(err.message); } @@ -287,10 +287,10 @@ export function combineOptionsForBuilder( return combined; } -export async function combineOptionsForSchematic( +export async function combineOptionsForGenerator( commandLineOpts: Options, collectionName: string, - schematicName: string, + generatorName: string, ws: WorkspaceDefinition, schema: Schema, isInteractive: boolean @@ -298,11 +298,20 @@ export async function combineOptionsForSchematic( const schematicDefaults = ws.schematics && ws.schematics[collectionName] && - ws.schematics[collectionName][schematicName] - ? ws.schematics[collectionName][schematicName] + ws.schematics[collectionName][generatorName] + ? ws.schematics[collectionName][generatorName] + : {}; + const generatorDefaults = + ws.generators && + ws.generators[collectionName] && + ws.generators[collectionName][generatorName] + ? ws.generators[collectionName][generatorName] : {}; let combined = convertAliases( - coerceTypesInOptions({ ...schematicDefaults, ...commandLineOpts }, schema), + coerceTypesInOptions( + { ...schematicDefaults, ...generatorDefaults, ...commandLineOpts }, + schema + ), schema, false ); diff --git a/packages/tao/src/shared/print-help.ts b/packages/tao/src/shared/print-help.ts index 5a5c7f9c65..cfab705c50 100644 --- a/packages/tao/src/shared/print-help.ts +++ b/packages/tao/src/shared/print-help.ts @@ -33,14 +33,3 @@ ${args} ${formatOption('help', 'Show available options for project target.')} `); } - -export let commandName = 'nx'; -export let toolDescription = 'Nx - Extensible Dev Tools for Monorepos.'; - -export function setCommandNameAndDescription( - name: string, - description: string -) { - commandName = name; - toolDescription = description; -} diff --git a/packages/tao/src/shared/workspace.ts b/packages/tao/src/shared/workspace.ts index fb7cacc299..dafe3b6fa5 100644 --- a/packages/tao/src/shared/workspace.ts +++ b/packages/tao/src/shared/workspace.ts @@ -6,6 +6,7 @@ export interface WorkspaceDefinition { projects: { [projectName: string]: ProjectDefinition }; defaultProject: string | undefined; schematics: { [collectionName: string]: { [schematicName: string]: any } }; + generators: { [collectionName: string]: { [generatorName: string]: any } }; cli: { defaultCollection: string }; } @@ -43,8 +44,8 @@ export class Workspaces { return schema['cli'] === 'nx'; } - isNxSchematic(collectionName: string, schematicName: string) { - const schema = this.readSchematic(collectionName, schematicName).schema; + isNxGenerator(collectionName: string, generatorName: string) { + const schema = this.readGenerator(collectionName, generatorName).schema; return schema['cli'] === 'nx'; } @@ -65,29 +66,29 @@ export class Workspaces { } } - readSchematic(collectionName: string, schematicName: string) { + readGenerator(collectionName: string, generatorName: string) { try { const { - schematicsFilePath, - schematicsJson, - normalizedSchematicName, - } = this.readSchematicsJson(collectionName, schematicName); - const schematicsDir = path.dirname(schematicsFilePath); - const schematicConfig = - schematicsJson.schematics[normalizedSchematicName]; - const schemaPath = path.join(schematicsDir, schematicConfig.schema || ''); + generatorsFilePath, + generatorsJson, + normalizedGeneratorName, + } = this.readGeneratorsJson(collectionName, generatorName); + const generatorsDir = path.dirname(generatorsFilePath); + const generatorConfig = (generatorsJson.generators || + generatorsJson.schematics)[normalizedGeneratorName]; + const schemaPath = path.join(generatorsDir, generatorConfig.schema || ''); const schema = JSON.parse(fs.readFileSync(schemaPath).toString()); const module = require(path.join( - schematicsDir, - schematicConfig.implementation - ? schematicConfig.implementation - : schematicConfig.factory + generatorsDir, + generatorConfig.implementation + ? generatorConfig.implementation + : generatorConfig.factory )); const implementation = module.default; return { schema, implementation }; } catch (e) { throw new Error( - `Unable to resolve ${collectionName}:${schematicName}.\n${e.message}` + `Unable to resolve ${collectionName}:${generatorName}.\n${e.message}` ); } } @@ -111,50 +112,50 @@ export class Workspaces { return { builder, buildersFilePath, buildersJson }; } - private readSchematicsJson(collectionName: string, schematic: string) { - let schematicsFilePath; + private readGeneratorsJson(collectionName: string, generator: string) { + let generatorsFilePath; if (collectionName.endsWith('.json')) { - schematicsFilePath = require.resolve(collectionName); + generatorsFilePath = require.resolve(collectionName); } else { const packageJsonPath = require.resolve(`${collectionName}/package.json`); const packageJson = JSON.parse( fs.readFileSync(packageJsonPath).toString() ); - const schematicsFile = packageJson.schematics; - schematicsFilePath = require.resolve( - path.join(path.dirname(packageJsonPath), schematicsFile) + const generatorsFile = packageJson.generators + ? packageJson.generators + : packageJson.schematics; + generatorsFilePath = require.resolve( + path.join(path.dirname(packageJsonPath), generatorsFile) ); } - const schematicsJson = JSON.parse( - fs.readFileSync(schematicsFilePath).toString() + const generatorsJson = JSON.parse( + fs.readFileSync(generatorsFilePath).toString() ); - let normalizedSchematicName; - for (let k of Object.keys(schematicsJson.schematics)) { - if (k === schematic) { - normalizedSchematicName = k; + let normalizedGeneratorName; + const gens = generatorsJson.generators || generatorsJson.schematics; + for (let k of Object.keys(gens)) { + if (k === generator) { + normalizedGeneratorName = k; break; } - if ( - schematicsJson.schematics[k].aliases && - schematicsJson.schematics[k].aliases.indexOf(schematic) > -1 - ) { - normalizedSchematicName = k; + if (gens[k].aliases && gens[k].aliases.indexOf(generator) > -1) { + normalizedGeneratorName = k; break; } } - if (!normalizedSchematicName) { - for (let parent of schematicsJson.extends || []) { + if (!normalizedGeneratorName) { + for (let parent of generatorsJson.extends || []) { try { - return this.readSchematicsJson(parent, schematic); + return this.readGeneratorsJson(parent, generator); } catch (e) {} } throw new Error( - `Cannot find schematic '${schematic}' in ${schematicsFilePath}.` + `Cannot find generator '${generator}' in ${generatorsFilePath}.` ); } - return { schematicsFilePath, schematicsJson, normalizedSchematicName }; + return { generatorsFilePath, generatorsJson, normalizedGeneratorName }; } } diff --git a/packages/workspace/collection.json b/packages/workspace/collection.json index 9b559bbff8..980e385c5f 100644 --- a/packages/workspace/collection.json +++ b/packages/workspace/collection.json @@ -58,10 +58,11 @@ "description": "Create a library" }, - "workspace-schematic": { - "factory": "./src/schematics/workspace-schematic/workspace-schematic", - "schema": "./src/schematics/workspace-schematic/schema.json", - "description": "Generates a workspace schematic" + "workspace-generator": { + "factory": "./src/schematics/workspace-generator/workspace-generator", + "schema": "./src/schematics/workspace-generator/schema.json", + "aliases": ["workspace-schematic"], + "description": "Generates a workspace generator" }, "run-commands": { diff --git a/packages/workspace/index.ts b/packages/workspace/index.ts index 662d939e0f..8093288bef 100644 --- a/packages/workspace/index.ts +++ b/packages/workspace/index.ts @@ -87,6 +87,6 @@ import * as strings from './src/utils/strings'; export { checkAndCleanWithSemver } from './src/utils/version-utils'; export { updatePackagesInPackageJson } from './src/utils/update-packages-in-package-json'; -export { librarySchematic } from './src/schematics/library/library'; +export { libraryGenerator } from './src/schematics/library/library'; export const stringUtils = strings; diff --git a/packages/workspace/src/command-line/nx-commands.ts b/packages/workspace/src/command-line/nx-commands.ts index 9fa27af8d1..1bb24d929a 100644 --- a/packages/workspace/src/command-line/nx-commands.ts +++ b/packages/workspace/src/command-line/nx-commands.ts @@ -8,7 +8,7 @@ import { format } from './format'; import { workspaceLint } from './lint'; import { list } from './list'; import { report } from './report'; -import { workspaceSchematic } from './workspace-schematic'; +import { workspaceGenerators } from './workspace-generators'; import { affected } from './affected'; import { runMany } from './run-many'; @@ -34,7 +34,7 @@ export const commandsObject = yargs ` ) .command( - 'generate [schematic-collection:][schematic] [options, ...]', + 'generate [collection:][generator] [options, ...]', ` Generate code (e.g., nx generate @nrwl/web:app myapp). @@ -150,26 +150,26 @@ export const commandsObject = yargs (_) => workspaceLint() ) .command( - 'workspace-schematic [name]', - 'Runs a workspace schematic from the tools/schematics directory', + ['workspace-generator [name]', 'workspace-schematic [name]'], + 'Runs a workspace generator from the tools/generators directory', (yargs) => { - yargs.option('list-schematics', { - describe: 'List the available workspace-schematics', + yargs.option('list-generators', { + describe: 'List the available workspace-generators', type: 'boolean', }); /** * Don't require `name` if only listing available * schematics */ - if (yargs.argv.listSchematics !== true) { + if (yargs.argv.listGenerators !== true) { yargs.demandOption(['name']).positional('name', { type: 'string', - describe: 'The name of your schematic`', + describe: 'The name of your generator`', }); } return yargs; }, - () => workspaceSchematic(process.argv.slice(3)) + () => workspaceGenerators(process.argv.slice(3)) ) .command( 'migrate', diff --git a/packages/workspace/src/command-line/supported-nx-commands.ts b/packages/workspace/src/command-line/supported-nx-commands.ts index 550a8be07c..a31752814e 100644 --- a/packages/workspace/src/command-line/supported-nx-commands.ts +++ b/packages/workspace/src/command-line/supported-nx-commands.ts @@ -13,6 +13,7 @@ export const supportedNxCommands = [ 'format:check', 'format:write', 'workspace-schematic', + 'workspace-generator', 'workspace-lint', 'migrate', 'report', diff --git a/packages/workspace/src/command-line/workspace-schematic.ts b/packages/workspace/src/command-line/workspace-generators.ts similarity index 89% rename from packages/workspace/src/command-line/workspace-schematic.ts rename to packages/workspace/src/command-line/workspace-generators.ts index 2b83dde71c..57b912d2f8 100644 --- a/packages/workspace/src/command-line/workspace-schematic.ts +++ b/packages/workspace/src/command-line/workspace-generators.ts @@ -46,7 +46,7 @@ type TsConfig = { references?: Array<{ path: string }>; }; -export async function workspaceSchematic(args: string[]) { +export async function workspaceGenerators(args: string[]) { const outDir = compileTools(); const parsedArgs = parseOptions(args, outDir); const logger = createConsoleLogger( @@ -54,16 +54,16 @@ export async function workspaceSchematic(args: string[]) { process.stdout, process.stderr ); - const collectionFile = path.join(outDir, 'workspace-schematics.json'); - if (parsedArgs.listSchematics) { - return listSchematics(collectionFile, logger); + const collectionFile = path.join(outDir, 'workspace-generators.json'); + if (parsedArgs.listGenerators) { + return listGenerators(collectionFile, logger); } - const schematicName = args[0]; + const generatorName = args[0]; const ws = new Workspaces(); - if (ws.isNxSchematic(collectionFile, schematicName)) { + if (ws.isNxGenerator(collectionFile, generatorName)) { try { execSync( - `npx tao g "${collectionFile}":${schematicName} ${args + `npx tao g "${collectionFile}":${generatorName} ${args .slice(1) .join(' ')}`, { stdio: ['inherit', 'inherit', 'inherit'] } @@ -74,8 +74,8 @@ export async function workspaceSchematic(args: string[]) { } else { try { const workflow = createWorkflow(parsedArgs.dryRun); - await executeSchematic( - schematicName, + await executeAngularDevkitSchematic( + generatorName, parsedArgs, workflow, outDir, @@ -93,10 +93,10 @@ function compileTools() { removeSync(toolsOutDir); compileToolsDir(toolsOutDir); - const schematicsOutDir = path.join(toolsOutDir, 'schematics'); + const generatorsOutDir = path.join(toolsOutDir, 'generators'); const collectionData = constructCollection(); - saveCollection(schematicsOutDir, collectionData); - return schematicsOutDir; + saveCollection(generatorsOutDir, collectionData); + return generatorsOutDir; } function getToolsOutDir() { @@ -104,10 +104,10 @@ function getToolsOutDir() { } function compileToolsDir(outDir: string) { - copySync(schematicsDir(), path.join(outDir, 'schematics')); + copySync(generatorsDir(), path.join(outDir, 'generators')); const tmpTsConfigPath = createTmpTsConfig(toolsTsConfigPath(), { - include: [path.join(schematicsDir(), '**/*.ts')], + include: [path.join(generatorsDir(), '**/*.ts')], }); const packageExec = getPackageManagerExecuteCommand(); @@ -123,11 +123,11 @@ function compileToolsDir(outDir: string) { } function constructCollection() { - const schematics = {}; - fs.readdirSync(schematicsDir()).forEach((c) => { - const childDir = path.join(schematicsDir(), c); + const generators = {}; + fs.readdirSync(generatorsDir()).forEach((c) => { + const childDir = path.join(generatorsDir(), c); if (exists(path.join(childDir, 'schema.json'))) { - schematics[c] = { + generators[c] = { factory: `./${c}`, schema: `./${path.join(c, 'schema.json')}`, description: `Schematic ${c}`, @@ -135,21 +135,21 @@ function constructCollection() { } }); return { - name: 'workspace-schematics', + name: 'workspace-generators', version: '1.0', - schematics, + schematics: generators, // TODO vsavkin: remove this }; } function saveCollection(dir: string, collection: any) { writeFileSync( - path.join(dir, 'workspace-schematics.json'), + path.join(dir, 'workspace-generators.json'), JSON.stringify(collection) ); } -function schematicsDir() { - return path.join(rootDirectory, 'tools', 'schematics'); +function generatorsDir() { + return path.join(rootDirectory, 'tools', 'generators'); } function toolsDir() { @@ -176,7 +176,7 @@ function createWorkflow(dryRun: boolean) { }); } -function listSchematics(collectionName: string, logger: logging.Logger) { +function listGenerators(collectionName: string, logger: logging.Logger) { try { const engineHost = new NodeModulesEngineHost(); const engine = new SchematicEngine(engineHost); @@ -234,7 +234,7 @@ function createPromptProvider(): schema.PromptProvider { } // execute schematic -async function executeSchematic( +async function executeAngularDevkitSchematic( schematicName: string, options: { [p: string]: any }, workflow: NodeWorkflow, @@ -374,7 +374,7 @@ function parseOptions(args: string[], outDir: string): { [k: string]: any } { } } return yargsParser(args, { - boolean: ['dryRun', 'listSchematics', 'interactive', ...booleanProps], + boolean: ['dryRun', 'listGenerators', 'interactive', ...booleanProps], alias: { dryRun: ['d'], listSchematics: ['l'], diff --git a/packages/workspace/src/schematics/library/library.ts b/packages/workspace/src/schematics/library/library.ts index 68bd3e74c4..eb2eeb3a71 100644 --- a/packages/workspace/src/schematics/library/library.ts +++ b/packages/workspace/src/schematics/library/library.ts @@ -143,7 +143,7 @@ export default function (schema: Schema): Rule { }; } -export const librarySchematic = wrapAngularDevkitSchematic( +export const libraryGenerator = wrapAngularDevkitSchematic( '@nrwl/workspace', 'library' ); diff --git a/packages/workspace/src/schematics/workspace-schematic/files/index.ts__tmpl__ b/packages/workspace/src/schematics/workspace-generator/files/index.ts__tmpl__ similarity index 66% rename from packages/workspace/src/schematics/workspace-schematic/files/index.ts__tmpl__ rename to packages/workspace/src/schematics/workspace-generator/files/index.ts__tmpl__ index 94c550393a..8d40a5d94d 100644 --- a/packages/workspace/src/schematics/workspace-schematic/files/index.ts__tmpl__ +++ b/packages/workspace/src/schematics/workspace-generator/files/index.ts__tmpl__ @@ -1,8 +1,8 @@ import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit'; -import { librarySchematic } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/workspace'; export default async function(host: Tree, schema: any) { - await librarySchematic({name: schema.name})(host); + await libraryGenerator({name: schema.name})(host); await formatFiles(host); return () => { installPackagesTask(host) diff --git a/packages/workspace/src/schematics/workspace-schematic/files/schema.json__tmpl__ b/packages/workspace/src/schematics/workspace-generator/files/schema.json__tmpl__ similarity index 100% rename from packages/workspace/src/schematics/workspace-schematic/files/schema.json__tmpl__ rename to packages/workspace/src/schematics/workspace-generator/files/schema.json__tmpl__ diff --git a/packages/workspace/src/schematics/workspace-schematic/schema.d.ts b/packages/workspace/src/schematics/workspace-generator/schema.d.ts similarity index 100% rename from packages/workspace/src/schematics/workspace-schematic/schema.d.ts rename to packages/workspace/src/schematics/workspace-generator/schema.d.ts diff --git a/packages/workspace/src/schematics/workspace-schematic/schema.json b/packages/workspace/src/schematics/workspace-generator/schema.json similarity index 100% rename from packages/workspace/src/schematics/workspace-schematic/schema.json rename to packages/workspace/src/schematics/workspace-generator/schema.json diff --git a/packages/workspace/src/schematics/workspace-schematic/workspace-schematic.spec.ts b/packages/workspace/src/schematics/workspace-generator/workspace-generator.spec.ts similarity index 50% rename from packages/workspace/src/schematics/workspace-schematic/workspace-schematic.spec.ts rename to packages/workspace/src/schematics/workspace-generator/workspace-generator.spec.ts index 67e475ef96..23654e95f6 100644 --- a/packages/workspace/src/schematics/workspace-schematic/workspace-schematic.spec.ts +++ b/packages/workspace/src/schematics/workspace-generator/workspace-generator.spec.ts @@ -1,7 +1,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import workspaceSchematic from './workspace-schematic'; +import workspaceGenerator from './workspace-generator'; -describe('workspace-schematic', () => { +describe('workspace-generator', () => { it('should generate a target', async () => { const tree = createTreeWithEmptyWorkspace(); const opts = { @@ -9,9 +9,9 @@ describe('workspace-schematic', () => { skipFormat: true, }; - await workspaceSchematic(tree, opts); + await workspaceGenerator(tree, opts); - expect(tree.exists('tools/schematics/custom/index.ts')).toBeTruthy(); - expect(tree.exists('tools/schematics/custom/schema.json')).toBeTruthy(); + expect(tree.exists('tools/generators/custom/index.ts')).toBeTruthy(); + expect(tree.exists('tools/generators/custom/schema.json')).toBeTruthy(); }); }); diff --git a/packages/workspace/src/schematics/workspace-schematic/workspace-schematic.ts b/packages/workspace/src/schematics/workspace-generator/workspace-generator.ts similarity index 92% rename from packages/workspace/src/schematics/workspace-schematic/workspace-schematic.ts rename to packages/workspace/src/schematics/workspace-generator/workspace-generator.ts index 2eb6017fc8..d17b9948f6 100644 --- a/packages/workspace/src/schematics/workspace-schematic/workspace-schematic.ts +++ b/packages/workspace/src/schematics/workspace-generator/workspace-generator.ts @@ -8,7 +8,7 @@ export default async function (host: Tree, schema: Schema) { generateFiles( host, path.join(__dirname, 'files'), - path.join('tools/schematics', schema.name), + path.join('tools/generators', schema.name), options ); if (!schema.skipFormat) { diff --git a/packages/workspace/src/schematics/workspace/files/package.json__tmpl__ b/packages/workspace/src/schematics/workspace/files/package.json__tmpl__ index 25cd8b9093..b49eecfcf6 100644 --- a/packages/workspace/src/schematics/workspace/files/package.json__tmpl__ +++ b/packages/workspace/src/schematics/workspace/files/package.json__tmpl__ @@ -24,16 +24,8 @@ "format": "nx format:write", "format:write": "nx format:write", "format:check": "nx format:check", - - <% if(cli === 'angular') { %> - "update": "ng update @nrwl/workspace", - <% } %> - - <% if(cli === 'nx') { %> "update": "nx migrate latest", - <% } %> - - "workspace-schematic": "nx workspace-schematic", + "workspace-generator": "nx workspace-generator", "dep-graph": "nx dep-graph", "help": "nx help" }, diff --git a/packages/workspace/src/schematics/workspace/files/tools/schematics/.gitkeep b/packages/workspace/src/schematics/workspace/files/tools/generators/.gitkeep similarity index 100% rename from packages/workspace/src/schematics/workspace/files/tools/schematics/.gitkeep rename to packages/workspace/src/schematics/workspace/files/tools/generators/.gitkeep diff --git a/packages/workspace/src/utils/plugins/core-plugins.ts b/packages/workspace/src/utils/plugins/core-plugins.ts index ce07cf8847..8bbd4eca74 100644 --- a/packages/workspace/src/utils/plugins/core-plugins.ts +++ b/packages/workspace/src/utils/plugins/core-plugins.ts @@ -6,19 +6,19 @@ export function fetchCorePlugins() { const corePlugins: CorePlugin[] = [ { name: '@nrwl/angular', - capabilities: 'schematics', + capabilities: 'generators', }, { name: '@nrwl/cypress', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/express', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/jest', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/linter', @@ -26,35 +26,35 @@ export function fetchCorePlugins() { }, { name: '@nrwl/nest', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/next', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/node', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/nx-plugin', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/react', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/storybook', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/web', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, { name: '@nrwl/workspace', - capabilities: 'builders,schematics', + capabilities: 'builders,generators', }, ]; return corePlugins; diff --git a/packages/workspace/src/utils/plugins/installed-plugins.ts b/packages/workspace/src/utils/plugins/installed-plugins.ts index 403c480d4b..611f7bfa73 100644 --- a/packages/workspace/src/utils/plugins/installed-plugins.ts +++ b/packages/workspace/src/utils/plugins/installed-plugins.ts @@ -32,7 +32,7 @@ export function getInstalledPluginsFromPackageJson( }) .sort() .map((name) => getPluginCapabilities(workspaceRoot, name)) - .filter((x) => x && !!(x.schematics || x.builders)); + .filter((x) => x && !!(x.generators || x.builders)); } export function listInstalledPlugins(installedPlugins: PluginCapabilities[]) { @@ -43,8 +43,8 @@ export function listInstalledPlugins(installedPlugins: PluginCapabilities[]) { if (hasElements(p.builders)) { capabilities.push('builders'); } - if (hasElements(p.schematics)) { - capabilities.push('schematics'); + if (hasElements(p.generators)) { + capabilities.push('generators'); } return `${terminal.bold(p.name)} (${capabilities.join()})`; }), diff --git a/packages/workspace/src/utils/plugins/models.ts b/packages/workspace/src/utils/plugins/models.ts index 57561297a5..2af952320d 100644 --- a/packages/workspace/src/utils/plugins/models.ts +++ b/packages/workspace/src/utils/plugins/models.ts @@ -1,4 +1,4 @@ -export interface PluginSchematic { +export interface PluginGenerator { factory: string; schema: string; description: string; @@ -15,12 +15,12 @@ export interface PluginBuilder { export interface PluginCapabilities { name: string; builders: { [name: string]: PluginBuilder }; - schematics: { [name: string]: PluginSchematic }; + generators: { [name: string]: PluginGenerator }; } export interface CorePlugin { name: string; - capabilities: 'builders' | 'schematics' | 'builders,schematics'; + capabilities: 'builders' | 'generators' | 'builders,generators'; link?: string; } diff --git a/packages/workspace/src/utils/plugins/plugin-capabilities.ts b/packages/workspace/src/utils/plugins/plugin-capabilities.ts index 63cff44933..9cfaa94848 100644 --- a/packages/workspace/src/utils/plugins/plugin-capabilities.ts +++ b/packages/workspace/src/utils/plugins/plugin-capabilities.ts @@ -40,12 +40,19 @@ export function getPluginCapabilities( const packageJson = readJsonFile(packageJsonPath); return { name: pluginName, - schematics: tryGetCollection( - workspaceRoot, - pluginName, - packageJson.schematics, - 'schematics' - ), + generators: + tryGetCollection( + workspaceRoot, + pluginName, + packageJson.generators, + 'generators' + ) || + tryGetCollection( + workspaceRoot, + pluginName, + packageJson.schematics, + 'schematics' + ), builders: tryGetCollection( workspaceRoot, pluginName, @@ -77,22 +84,22 @@ export function listPluginCapabilities(pluginName: string) { } const hasBuilders = hasElements(plugin.builders); - const hasSchematics = hasElements(plugin.schematics); + const hasGenerators = hasElements(plugin.generators); - if (!hasBuilders && !hasSchematics) { + if (!hasBuilders && !hasGenerators) { output.warn({ title: `No capabilities found in ${pluginName}` }); return; } const bodyLines = []; - if (hasSchematics) { - bodyLines.push(terminal.bold(terminal.green('SCHEMATICS'))); + if (hasGenerators) { + bodyLines.push(terminal.bold(terminal.green('GENERATORS'))); bodyLines.push(''); bodyLines.push( - ...Object.keys(plugin.schematics).map( + ...Object.keys(plugin.generators).map( (name) => - `${terminal.bold(name)} : ${plugin.schematics[name].description}` + `${terminal.bold(name)} : ${plugin.generators[name].description}` ) ); if (hasBuilders) {