Skip to content

Commit

Permalink
fix(core): Remove nameAndDirectoryFormat option from generators (#28110)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

Currently, when we use generator's via the CLI passing the `name` arg
has more than one responsibility:
1.  it can be used as a path
2. it can be used as the generator's name (e.g. Component name)

This is not intuitive as if we use via Nx Console because it creates
some ambiguity around the `--name` property which is normally described
as only 2.

![image](https://github.com/user-attachments/assets/b05fa2a7-36e7-44a1-af82-6f55f53d6c43)

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

What is expected is that the `name` property should only have the
responsibility of determining the name of the generated module
(Component, Directive etc...).

The new property `path` replaces the `directory` property but fulfils
the same purpose as determining where the module should be created.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

---------

Co-authored-by: Jack Hsu <[email protected]>
  • Loading branch information
ndcunningham and jaysoo authored Oct 1, 2024
1 parent e802d2c commit bc8b71a
Show file tree
Hide file tree
Showing 187 changed files with 1,154 additions and 1,807 deletions.
20 changes: 7 additions & 13 deletions docs/generated/packages/angular/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
"description": "Creates a new Angular component.",
"additionalProperties": false,
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the component.",
"description": "The path at which to create the component file, relative to the workspace root. By default, it is set to the root of the project.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the component?"
"x-prompt": "Where to create the component?"
},
"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 workspace root.",
"aliases": ["dir", "path"],
"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`).",
"name": {
"type": "string",
"enum": ["as-provided", "derived"]
"description": "The name of the component.",
"x-prompt": "What name would you like to use for the component?"
},
"prefix": {
"type": "string",
Expand Down Expand Up @@ -118,7 +112,7 @@
"x-priority": "internal"
}
},
"required": ["name"],
"required": ["path"],
"examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Component\" %}\n\nCreate a component named `my-component`:\n\n```bash\nnx g @nx/angular:component apps/my-app/src/lib/my-component/my-component\n```\n\n{% /tab %}\n\n{% tab label=\"Single File Component\" %}\n\nCreate a component named `my-component` with inline styles and inline template:\n\n```bash\nnx g @nx/angular:component apps/my-app/src/lib/my-component/my-component --inlineStyle --inlineTemplate\n```\n\n{% /tab %}\n\n{% tab label=\"Component with OnPush Change Detection Strategy\" %}\n\nCreate a component named `my-component` with OnPush Change Detection Strategy:\n\n```bash\nnx g @nx/angular:component apps/my-app/src/lib/my-component/my-component --changeDetection=OnPush\n```\n\n{% /tab %}\n",
"presets": []
},
Expand Down
20 changes: 7 additions & 13 deletions docs/generated/packages/angular/generators/directive.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
"description": "Creates a new Angular directive.",
"additionalProperties": false,
"properties": {
"path": {
"type": "string",
"description": "The path at which to create the directive file.",
"x-prompt": "Where to put the directive?",
"$default": { "$source": "argv", "index": 0 }
},
"name": {
"type": "string",
"description": "The name of the new directive.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the directive?"
},
"directory": {
"type": "string",
"description": "The directory at which to create the directive file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
"aliases": ["dir", "path"],
"x-priority": "important"
},
"nameAndDirectoryFormat": {
"description": "Whether to generate the directive 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"]
},
"prefix": {
"type": "string",
"description": "A prefix to apply to generated selectors.",
Expand Down Expand Up @@ -72,7 +66,7 @@
"description": "Skip formatting of files."
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"aliases": ["d"],
Expand Down
27 changes: 7 additions & 20 deletions docs/generated/packages/angular/generators/pipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,16 @@
"additionalProperties": false,
"description": "Creates an Angular pipe.",
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the pipe.",
"description": "The path at which to create the pipe file, relative to the workspace root.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the pipe?"
},
"directory": {
"type": "string",
"description": "The directory at which to create the pipe file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
"aliases": ["dir", "path"],
"x-priority": "important"
"x-prompt": "What is the path of the new pipe?"
},
"nameAndDirectoryFormat": {
"description": "Whether to generate the pipe 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"]
},
"project": {
"name": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "projectName" },
"x-dropdown": "projects",
"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 v20."
"description": "The name of the pipe.",
"x-prompt": "What name would you like to use for the pipe?"
},
"skipTests": {
"type": "boolean",
Expand Down Expand Up @@ -65,7 +52,7 @@
"description": "Skip formatting of files."
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Generate an Angular Pipe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
"description": "Creates a new, generic Angular directive definition in the given or default project.",
"additionalProperties": false,
"properties": {
"path": {
"type": "string",
"description": "The path at which to create the SCAM Directive files, relative to the workspace root.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What is the path of the new directive?"
},
"name": {
"type": "string",
"description": "The name of the directive.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the directive?",
"x-priority": "important"
},
Expand Down Expand Up @@ -85,7 +90,7 @@
"x-priority": "internal"
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Generate a directive with an accompanying Single Component Angular Module (SCAM).",
Expand Down
29 changes: 8 additions & 21 deletions docs/generated/packages/angular/generators/scam-pipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,25 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/angular:scam-pipe --project=my-lib --flat=false my-transformation",
"command": "nx g @nx/angular:scam-pipe mylib/src/lib/my-transformation/my-transformation",
"description": "Generates a `MyTransformationPipe` in a `my-transformation` folder in the `my-lib` project"
}
],
"description": "Creates a new, generic Angular pipe definition in the given or default project.",
"additionalProperties": false,
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the pipe.",
"description": "The path at which to create the pipe file, relative to the workspace root.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the pipe?",
"x-priority": "important"
"x-prompt": "What is the path of the new pipe?"
},
"directory": {
"name": {
"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 workspace root.",
"aliases": ["dir", "path"],
"description": "The name of the pipe.",
"x-prompt": "What name would you like to use for the pipe?",
"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"]
},
"project": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "projectName" },
"x-dropdown": "projects",
"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 v20."
},
"skipTests": {
"type": "boolean",
"description": "Do not create `spec.ts` test files for the new pipe.",
Expand Down Expand Up @@ -71,7 +58,7 @@
"x-priority": "internal"
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Generate a pipe with an accompanying Single Component Angular Module (SCAM).",
Expand Down
29 changes: 8 additions & 21 deletions docs/generated/packages/angular/generators/scam.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,23 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/angular:scam my-sample --directory=my-lib/src/lib/my-sample",
"command": "nx g @nx/angular:scam my-lib/src/lib/my-sample/my-sample",
"description": "Generate a `MySampleComponent` component in the `my-lib` library."
}
],
"description": "Creates a new Angular SCAM.",
"additionalProperties": false,
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the component.",
"description": "The path at which to create the SCAM file, relative to the workspace root.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the component?"
},
"directory": {
"type": "string",
"description": "The directory at which to create the SCAM files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
"aliases": ["dir", "path"],
"x-priority": "important"
"x-prompt": "What is the path of the new SCAM?"
},
"nameAndDirectoryFormat": {
"description": "Whether to generate the SCAM 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"]
},
"project": {
"name": {
"type": "string",
"description": "The name of the project.",
"$default": { "$source": "projectName" },
"x-dropdown": "projects",
"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 v20."
"description": "The name of the component.",
"x-prompt": "What name would you like to use for the component?"
},
"displayBlock": {
"description": "Specifies if the style will contain `:host { display: block; }`.",
Expand Down Expand Up @@ -125,7 +112,7 @@
"x-priority": "internal"
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Generate a component with an accompanying Single Component Angular Module (SCAM).",
Expand Down
24 changes: 10 additions & 14 deletions docs/generated/packages/expo/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@
"type": "object",
"examples": [
{
"command": "g @nx/expo:component my-component --directory=mylib/my-component",
"command": "g @nx/expo:component mylib/my-component --name my-component",
"description": "Generate a component in the mylib library"
},
{
"command": "g @nx/expo:component my-component --directory=mylib/my-component --classComponent",
"command": "g @nx/expo:component mylib/my-component --name my-component --classComponent",
"description": "Generate a class component in the mylib library"
}
],
"properties": {
"path": {
"type": "string",
"description": "Path where the component will be generated.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "Where should the component be generated?",
"x-priority": "important"
},
"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": {
Expand All @@ -40,16 +46,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).",
Expand All @@ -64,7 +60,7 @@
"default": false
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Create a component",
Expand Down
26 changes: 7 additions & 19 deletions docs/generated/packages/nest/generators/class.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@
"cli": "nx",
"type": "object",
"properties": {
"name": {
"description": "The name of the class.",
"path": {
"description": "Path where the class will be generated.",
"type": "string",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use?"
},
"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"]
"x-prompt": "Where should the class be generated?"
},
"project": {
"description": "The Nest project to target.",
"type": "string",
"$default": { "$source": "projectName" },
"alias": "p",
"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 v20."
},
"directory": {
"description": "Directory where the generated files are placed. when `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. otherwise, it will be relative to the workspace root.",
"name": {
"description": "The name of the class.",
"type": "string",
"aliases": ["dir", "path"]
"x-prompt": "What name would you like to use?"
},
"skipFormat": {
"description": "Skip formatting files.",
Expand All @@ -57,7 +45,7 @@
}
},
"additionalProperties": false,
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Run the `class` NestJS generator with Nx project support.",
Expand Down
19 changes: 7 additions & 12 deletions docs/generated/packages/nest/generators/controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@
"cli": "nx",
"type": "object",
"properties": {
"name": {
"description": "The name of the controller.",
"path": {
"description": "Path where the controller will be generated.",
"type": "string",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use?"
},
"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"]
"x-prompt": "Where should the controller be generated?"
},
"directory": {
"description": "Directory where the generated files are placed. when `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. otherwise, it will be relative to the workspace root.",
"name": {
"description": "The name of the controller.",
"type": "string",
"aliases": ["dir", "path"]
"x-prompt": "What name would you like to use?"
},
"skipFormat": {
"description": "Skip formatting files.",
Expand Down Expand Up @@ -53,7 +48,7 @@
}
},
"additionalProperties": false,
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Run the `controller` NestJS generator with Nx project support.",
Expand Down
Loading

0 comments on commit bc8b71a

Please sign in to comment.