Skip to content

Commit

Permalink
feat(react): support generating components using the path as provided
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Oct 13, 2023
1 parent 5516752 commit 90b7004
Show file tree
Hide file tree
Showing 39 changed files with 549 additions and 374 deletions.
19 changes: 12 additions & 7 deletions docs/generated/packages/expo/generators/component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "component",
"factory": "./src/generators/component/component#expoComponentGenerator",
"factory": "./src/generators/component/component#expoComponentGeneratorInternal",
"schema": {
"cli": "nx",
"$id": "NxExpoComponent",
Expand All @@ -22,8 +22,7 @@
"type": "string",
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this component?"
"$default": { "$source": "projectName" }
},
"name": {
"type": "string",
Expand All @@ -49,13 +48,19 @@
},
"directory": {
"type": "string",
"description": "Create the component under this directory (can be nested).",
"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"]
},
"flat": {
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"export": {
"type": "boolean",
Expand All @@ -77,12 +82,12 @@
"default": false
}
},
"required": ["name", "project"],
"required": ["name"],
"presets": []
},
"description": "Create a component",
"aliases": ["c"],
"implementation": "/packages/expo/src/generators/component/component#expoComponentGenerator.ts",
"implementation": "/packages/expo/src/generators/component/component#expoComponentGeneratorInternal.ts",
"hidden": false,
"path": "/packages/expo/src/generators/component/schema.json",
"type": "generator"
Expand Down
20 changes: 13 additions & 7 deletions docs/generated/packages/next/generators/component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "component",
"factory": "./src/generators/component/component#componentGenerator",
"factory": "./src/generators/component/component#componentGeneratorInternal",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
Expand All @@ -14,8 +14,8 @@
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this component?",
"x-priority": "important"
"x-priority": "important",
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -66,10 +66,15 @@
},
"directory": {
"type": "string",
"description": "Create the component under this directory (can be nested).",
"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.",
"alias": "dir",
"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).",
Expand All @@ -84,7 +89,8 @@
"flat": {
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"pascalCaseFiles": {
"type": "boolean",
Expand All @@ -105,12 +111,12 @@
"x-priority": "internal"
}
},
"required": ["name", "project"],
"required": ["name"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Create an app component\" %}\n\n```shell\nnx g component my-cmp --project=my-app\n```\n\n{% /tab %}\n{% tab label=\"Create a component without its own folder\" %}\n\nRunning the following will create a component under `apps/my-app/components/my-cmp.tsx` rather than `apps/my-app/components/my-cmp/my-cmp.tsx`.\n\n```shell\nnx g component my-cmp --flat --project=my-app\n```\n\n{% /tab %}\n{% tab label=\"Create component in a custom directory\" %}\n\nRunning the following will create a component under `apps/my-app/foo/my-cmp.tsx` rather than `apps/my-app/my-cmp/my-cmp.tsx`.\n\n```shell\nnx g component my-cmp --directory=foo --flat --project=my-app\n```\n\n{% /tab %}\n{% /tabs %}\n",
"presets": []
},
"description": "Create a component.",
"implementation": "/packages/next/src/generators/component/component#componentGenerator.ts",
"implementation": "/packages/next/src/generators/component/component#componentGeneratorInternal.ts",
"aliases": [],
"hidden": false,
"path": "/packages/next/src/generators/component/schema.json",
Expand Down
20 changes: 12 additions & 8 deletions docs/generated/packages/next/generators/page.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "page",
"factory": "./src/generators/page/page#pageGenerator",
"factory": "./src/generators/page/page#pageGeneratorInternal",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
Expand All @@ -13,9 +13,7 @@
"type": "string",
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this component?",
"x-priority": "important"
"$default": { "$source": "projectName" }
},
"name": {
"type": "string",
Expand All @@ -26,10 +24,15 @@
},
"directory": {
"type": "string",
"description": "Create the page under this directory (can be nested). Will be created under `pages/`.",
"description": "The directory at which to create the page file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
"alias": "dir",
"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"]
},
"style": {
"description": "The file extension to be used for style files.",
"type": "string",
Expand Down Expand Up @@ -84,7 +87,8 @@
"flat": {
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"skipFormat": {
"description": "Skip formatting files.",
Expand All @@ -93,12 +97,12 @@
"x-priority": "internal"
}
},
"required": ["name", "project"],
"required": ["name"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Create static page in an app\" %}\n\n```shell\nnx g page my-page --project=my-app\n```\n\n{% /tab %}\n{% tab label=\"Create dynamic page in an app\" %}\n\nThe following creates a page under `apps/my-app/pages/products/[id].tsx`.\n\n```shell\nnx g page \"[id]\" --project=my-app --directory=products\n```\n\n{% /tab %}\n\n{% /tabs %}\n",
"presets": []
},
"description": "Create a page.",
"implementation": "/packages/next/src/generators/page/page#pageGenerator.ts",
"implementation": "/packages/next/src/generators/page/page#pageGeneratorInternal.ts",
"aliases": [],
"hidden": false,
"path": "/packages/next/src/generators/page/schema.json",
Expand Down
18 changes: 12 additions & 6 deletions docs/generated/packages/react-native/generators/component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "component",
"factory": "./src/generators/component/component#reactNativeComponentGenerator",
"factory": "./src/generators/component/component#reactNativeComponentGeneratorInternal",
"schema": {
"cli": "nx",
"$id": "NxReactNativeApplication",
Expand All @@ -24,7 +24,7 @@
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this component?"
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
},
"name": {
"type": "string",
Expand All @@ -44,13 +44,19 @@
},
"directory": {
"type": "string",
"description": "Create the component under this directory (can be nested).",
"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"]
},
"flat": {
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"export": {
"type": "boolean",
Expand All @@ -72,12 +78,12 @@
"default": false
}
},
"required": ["name", "project"],
"required": ["name"],
"presets": []
},
"description": "Create a React Native component.",
"aliases": ["c"],
"implementation": "/packages/react-native/src/generators/component/component#reactNativeComponentGenerator.ts",
"implementation": "/packages/react-native/src/generators/component/component#reactNativeComponentGeneratorInternal.ts",
"hidden": false,
"path": "/packages/react-native/src/generators/component/schema.json",
"type": "generator"
Expand Down
30 changes: 13 additions & 17 deletions docs/generated/packages/react/generators/component.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
{
"name": "component",
"factory": "./src/generators/component/component#componentGenerator",
"factory": "./src/generators/component/component#componentGeneratorInternal",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "NxReactComponent",
"title": "Create a React Component",
"description": "Create a React Component for Nx.",
"type": "object",
"examples": [
{
"command": "nx g component my-component --project=mylib",
"description": "Generate a component in the `mylib` library"
},
{
"command": "nx g component my-component --project=mylib --classComponent",
"description": "Generate a class component in the `mylib` library"
}
],
"properties": {
"project": {
"type": "string",
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this component?",
"x-priority": "important"
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -81,14 +70,20 @@
},
"directory": {
"type": "string",
"description": "Create the component under this directory (can be nested).",
"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.",
"alias": "dir",
"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"]
},
"flat": {
"type": "boolean",
"description": "Create component at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"export": {
"type": "boolean",
Expand Down Expand Up @@ -140,12 +135,13 @@
"x-priority": "internal"
}
},
"required": ["name", "project"],
"required": ["name"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Component\" %}\n\nCreate a component named `my-component` under the `libs/ui` project:\n\n```bash\nnx g @nx/react:component libs/ui/src/my-component\n```\n\n{% /tab %}\n\n{% tab label=\"Standalone Component\" %}\n\nCreate a class component named `my-component` under the `libs/ui` project:\n\n```bash\nnx g @nx/react:component libs/ui/src/my-component --classComponent\n```\n\n{% /tab %}\n",
"presets": []
},
"description": "Create a React component.",
"aliases": ["c"],
"implementation": "/packages/react/src/generators/component/component#componentGenerator.ts",
"implementation": "/packages/react/src/generators/component/component#componentGeneratorInternal.ts",
"hidden": false,
"path": "/packages/react/src/generators/component/schema.json",
"type": "generator"
Expand Down
20 changes: 12 additions & 8 deletions docs/generated/packages/react/generators/hook.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hook",
"factory": "./src/generators/hook/hook#hookGenerator",
"factory": "./src/generators/hook/hook#hookGeneratorInternal",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
Expand All @@ -19,9 +19,7 @@
"type": "string",
"description": "The name of the project.",
"alias": "p",
"$default": { "$source": "projectName" },
"x-prompt": "What is the name of the project for this hook?",
"x-priority": "important"
"$default": { "$source": "projectName" }
},
"name": {
"type": "string",
Expand All @@ -43,13 +41,19 @@
},
"directory": {
"type": "string",
"description": "Create the hook under this directory (can be nested).",
"description": "The directory at which to create the hook 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"]
},
"flat": {
"type": "boolean",
"description": "Create hook at the source root rather than its own directory.",
"default": false
"default": false,
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
},
"export": {
"type": "boolean",
Expand All @@ -71,12 +75,12 @@
"default": false
}
},
"required": ["name", "project"],
"required": ["name"],
"presets": []
},
"description": "Create a hook.",
"aliases": ["c"],
"implementation": "/packages/react/src/generators/hook/hook#hookGenerator.ts",
"implementation": "/packages/react/src/generators/hook/hook#hookGeneratorInternal.ts",
"hidden": false,
"path": "/packages/react/src/generators/hook/schema.json",
"type": "generator"
Expand Down
Loading

0 comments on commit 90b7004

Please sign in to comment.