diff --git a/docs/generated/packages/react-native/generators/component.json b/docs/generated/packages/react-native/generators/component.json index 258b8d7ae3f704..22e4f0bbdd068a 100644 --- a/docs/generated/packages/react-native/generators/component.json +++ b/docs/generated/packages/react-native/generators/component.json @@ -10,19 +10,24 @@ "type": "object", "examples": [ { - "command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component", + "command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component ", "description": "Generate a component in the `mylib` library" }, { - "command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component --classComponent", + "command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component --classComponent", "description": "Generate a class component in the `mylib` library" } ], "properties": { + "path": { + "type": "string", + "description": "The path at which to create the component file.", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "What path would you like to use for the component?" + }, "name": { "type": "string", "description": "The name of the component.", - "$default": { "$source": "argv", "index": 0 }, "x-prompt": "What name would you like to use for the component?" }, "js": { @@ -35,16 +40,6 @@ "description": "When true, does not create `spec.ts` test files for the new component.", "default": false }, - "directory": { - "type": "string", - "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.", - "x-priority": "important" - }, - "nameAndDirectoryFormat": { - "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "export": { "type": "boolean", "description": "When true, the component is exported from the project `index.ts` (if it exists).", @@ -59,7 +54,7 @@ "default": false } }, - "required": ["name"], + "required": ["path"], "presets": [] }, "description": "Create a React Native component.", diff --git a/e2e/next/src/next-storybook.test.ts b/e2e/next/src/next-storybook.test.ts index 5eef599acfc17c..15ab50ad171483 100644 --- a/e2e/next/src/next-storybook.test.ts +++ b/e2e/next/src/next-storybook.test.ts @@ -18,7 +18,7 @@ describe('Next.js Storybook', () => { `generate @nx/next:app ${appName} --e2eTestRunner=none --project-name-and-root-format=as-provided --no-interactive` ); runCLI( - `generate @nx/next:component foo --directory=${appName}/components/foo --nameAndDirectoryFormat=as-provided --no-interactive` + `generate @nx/next:component ${appName}/components/foo/foo --no-interactive` ); }); diff --git a/e2e/react-native/src/react-native-legacy.test.ts b/e2e/react-native/src/react-native-legacy.test.ts index 13398ba8f9c323..a063609752d5c0 100644 --- a/e2e/react-native/src/react-native-legacy.test.ts +++ b/e2e/react-native/src/react-native-legacy.test.ts @@ -189,7 +189,7 @@ describe('@nx/react-native (legacy)', () => { const componentName = uniq('Component'); runCLI( - `generate @nx/react-native:component ${componentName} --directory=libs/${libName}/src/lib/${componentName} --export` + `generate @nx/react-native:component libs/${libName}/src/lib/${componentName}/${componentName} --export` ); expect(() => { runCLI(`build ${libName}`); diff --git a/e2e/react/src/cypress-component-tests.test.ts b/e2e/react/src/cypress-component-tests.test.ts index a4f97543352930..22d46e96d7c565 100644 --- a/e2e/react/src/cypress-component-tests.test.ts +++ b/e2e/react/src/cypress-component-tests.test.ts @@ -111,7 +111,7 @@ export default App;` `generate @nx/react:lib ${buildableLibName} --directory=libs/${buildableLibName} --buildable --no-interactive --unitTestRunner=jest` ); runCLI( - `generate @nx/react:component input --directory=libs/${buildableLibName}/src/lib/input --export --no-interactive` + `generate @nx/react:component libs/${buildableLibName}/src/lib/input/input --export --no-interactive` ); checkFilesExist(`libs/${buildableLibName}/src/lib/input/input.tsx`); diff --git a/packages/react-native/src/generators/component/lib/normalize-options.ts b/packages/react-native/src/generators/component/lib/normalize-options.ts index 8f79a97aca16bf..e9426cebb40478 100644 --- a/packages/react-native/src/generators/component/lib/normalize-options.ts +++ b/packages/react-native/src/generators/component/lib/normalize-options.ts @@ -3,6 +3,7 @@ import { Schema } from '../schema'; import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils'; export interface NormalizedSchema extends Schema { + directory: string; projectSourceRoot: string; fileName: string; className: string; @@ -14,8 +15,6 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { - assertValidOptions(options); - const { artifactName: name, directory, @@ -28,6 +27,8 @@ export async function normalizeOptions( fileExtension: 'tsx', }); + assertValidOptions({ name, directory }); + const project = getProjects(host).get(projectName); const { className } = names(name); @@ -44,6 +45,7 @@ export async function normalizeOptions( return { ...options, + name, directory, className, fileName, @@ -53,7 +55,7 @@ export async function normalizeOptions( }; } -function assertValidOptions(options: Schema) { +function assertValidOptions(options: { name: string; directory: string }) { const slashes = ['/', '\\']; slashes.forEach((s) => { if (options.name.indexOf(s) !== -1) { @@ -63,7 +65,7 @@ function assertValidOptions(options: Schema) { suggestion = `${options.directory}${s}${suggestion}`; } throw new Error( - `Found "${s}" in the component name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?` + `Found "${s}" in the component name. Did you mean to use the --path option (e.g. \`nx g c ${suggestion}/${name} \`)?` ); } }); diff --git a/packages/react-native/src/generators/component/schema.d.ts b/packages/react-native/src/generators/component/schema.d.ts index d99f98f91555a5..6e6edb5ec33463 100644 --- a/packages/react-native/src/generators/component/schema.d.ts +++ b/packages/react-native/src/generators/component/schema.d.ts @@ -5,7 +5,6 @@ export interface Schema { path: string; name?: string; skipTests?: boolean; - directory?: string; export?: boolean; classComponent?: boolean; js?: boolean; diff --git a/packages/react-native/src/generators/component/schema.json b/packages/react-native/src/generators/component/schema.json index 0730c908eb024b..3b8b3f55d3663c 100644 --- a/packages/react-native/src/generators/component/schema.json +++ b/packages/react-native/src/generators/component/schema.json @@ -7,22 +7,27 @@ "type": "object", "examples": [ { - "command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component", + "command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component ", "description": "Generate a component in the `mylib` library" }, { - "command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component --classComponent", + "command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component --classComponent", "description": "Generate a class component in the `mylib` library" } ], "properties": { - "name": { + "path": { "type": "string", - "description": "The name of the component.", + "description": "The path at which to create the component file.", "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "What path would you like to use for the component?" + }, + "name": { + "type": "string", + "description": "The name of the component.", "x-prompt": "What name would you like to use for the component?" }, "js": { @@ -35,16 +40,6 @@ "description": "When true, does not create `spec.ts` test files for the new component.", "default": false }, - "directory": { - "type": "string", - "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.", - "x-priority": "important" - }, - "nameAndDirectoryFormat": { - "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "export": { "type": "boolean", "description": "When true, the component is exported from the project `index.ts` (if it exists).", @@ -59,5 +54,5 @@ "default": false } }, - "required": ["name"] + "required": ["path"] }