From aa7625b76fcd3f53f6eda91220ecfd0a549928de Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Tue, 17 Oct 2023 18:14:36 -0400 Subject: [PATCH] feat(nest): update nest generators to support name and directory format option (#19668) Co-authored-by: FrozenPandaz --- .../packages/nest/generators/class.json | 16 +++++++--- .../packages/nest/generators/controller.json | 16 +++++++--- .../packages/nest/generators/decorator.json | 16 +++++++--- .../packages/nest/generators/filter.json | 16 +++++++--- .../packages/nest/generators/gateway.json | 16 +++++++--- .../packages/nest/generators/guard.json | 16 +++++++--- .../packages/nest/generators/interceptor.json | 16 +++++++--- .../packages/nest/generators/interface.json | 16 +++++++--- .../packages/nest/generators/middleware.json | 16 +++++++--- .../packages/nest/generators/module.json | 16 +++++++--- .../packages/nest/generators/pipe.json | 16 +++++++--- .../packages/nest/generators/provider.json | 16 +++++++--- .../packages/nest/generators/resolver.json | 11 ++++--- .../packages/nest/generators/resource.json | 11 ++++--- .../packages/nest/generators/service.json | 16 +++++++--- packages/nest/generators.json | 30 +++++++++--------- packages/nest/src/generators/class/class.ts | 26 +++++++++++++--- .../nest/src/generators/class/schema.json | 12 +++++-- .../src/generators/controller/controller.ts | 26 +++++++++++++--- .../src/generators/controller/schema.json | 12 +++++-- .../src/generators/decorator/decorator.ts | 26 +++++++++++++--- .../nest/src/generators/decorator/schema.json | 12 +++++-- packages/nest/src/generators/filter/filter.ts | 26 +++++++++++++--- .../nest/src/generators/filter/schema.json | 12 +++++-- .../nest/src/generators/gateway/gateway.ts | 26 +++++++++++++--- .../nest/src/generators/gateway/schema.json | 12 +++++-- packages/nest/src/generators/guard/guard.ts | 26 +++++++++++++--- .../nest/src/generators/guard/schema.json | 12 +++++-- .../src/generators/interceptor/interceptor.ts | 26 +++++++++++++--- .../src/generators/interceptor/schema.json | 12 +++++-- .../src/generators/interface/interface.ts | 19 ++++++++++-- .../nest/src/generators/interface/schema.json | 12 +++++-- .../src/generators/middleware/middleware.ts | 26 +++++++++++++--- .../src/generators/middleware/schema.json | 12 +++++-- packages/nest/src/generators/module/module.ts | 26 +++++++++++++--- .../nest/src/generators/module/schema.json | 12 +++++-- packages/nest/src/generators/pipe/pipe.ts | 26 +++++++++++++--- packages/nest/src/generators/pipe/schema.json | 12 +++++-- .../nest/src/generators/provider/provider.ts | 26 +++++++++++++--- .../nest/src/generators/provider/schema.json | 12 +++++-- .../nest/src/generators/resolver/resolver.ts | 26 +++++++++++++--- .../nest/src/generators/resolver/schema.json | 7 +++-- .../nest/src/generators/resource/resource.ts | 26 +++++++++++++--- .../nest/src/generators/resource/schema.json | 7 +++-- .../nest/src/generators/service/schema.json | 12 +++++-- .../nest/src/generators/service/service.ts | 26 +++++++++++++--- .../src/generators/utils/normalize-options.ts | 31 ++++++++++++------- packages/nest/src/generators/utils/types.ts | 3 ++ 48 files changed, 629 insertions(+), 218 deletions(-) diff --git a/docs/generated/packages/nest/generators/class.json b/docs/generated/packages/nest/generators/class.json index c704a6c24ea8a..900db44bd2221 100644 --- a/docs/generated/packages/nest/generators/class.json +++ b/docs/generated/packages/nest/generators/class.json @@ -1,6 +1,6 @@ { "name": "class", - "factory": "./src/generators/class/class", + "factory": "./src/generators/class/class#classGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestClassGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `class` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/class/class.ts", + "implementation": "/packages/nest/src/generators/class/class#classGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/class/schema.json", diff --git a/docs/generated/packages/nest/generators/controller.json b/docs/generated/packages/nest/generators/controller.json index d9b337ef92668..5f08cfa027536 100644 --- a/docs/generated/packages/nest/generators/controller.json +++ b/docs/generated/packages/nest/generators/controller.json @@ -1,6 +1,6 @@ { "name": "controller", - "factory": "./src/generators/controller/controller", + "factory": "./src/generators/controller/controller#controllerGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestControllerGenerator", @@ -20,10 +20,15 @@ "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." + }, + "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"] }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -60,11 +66,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `controller` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/controller/controller.ts", + "implementation": "/packages/nest/src/generators/controller/controller#controllerGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/controller/schema.json", diff --git a/docs/generated/packages/nest/generators/decorator.json b/docs/generated/packages/nest/generators/decorator.json index 20f955028e5d0..95a95191b8895 100644 --- a/docs/generated/packages/nest/generators/decorator.json +++ b/docs/generated/packages/nest/generators/decorator.json @@ -1,6 +1,6 @@ { "name": "decorator", - "factory": "./src/generators/decorator/decorator", + "factory": "./src/generators/decorator/decorator#decoratorGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestDecoratorGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -35,6 +40,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -45,11 +51,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `decorator` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/decorator/decorator.ts", + "implementation": "/packages/nest/src/generators/decorator/decorator#decoratorGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/decorator/schema.json", diff --git a/docs/generated/packages/nest/generators/filter.json b/docs/generated/packages/nest/generators/filter.json index ed7f5cae11298..bb64e189410f4 100644 --- a/docs/generated/packages/nest/generators/filter.json +++ b/docs/generated/packages/nest/generators/filter.json @@ -1,6 +1,6 @@ { "name": "filter", - "factory": "./src/generators/filter/filter", + "factory": "./src/generators/filter/filter#filterGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestFilterGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `filter` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/filter/filter.ts", + "implementation": "/packages/nest/src/generators/filter/filter#filterGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/filter/schema.json", diff --git a/docs/generated/packages/nest/generators/gateway.json b/docs/generated/packages/nest/generators/gateway.json index e067759f0b228..6ca5c53fae314 100644 --- a/docs/generated/packages/nest/generators/gateway.json +++ b/docs/generated/packages/nest/generators/gateway.json @@ -1,6 +1,6 @@ { "name": "gateway", - "factory": "./src/generators/gateway/gateway", + "factory": "./src/generators/gateway/gateway#gatewayGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestGatewayGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `gateway` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/gateway/gateway.ts", + "implementation": "/packages/nest/src/generators/gateway/gateway#gatewayGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/gateway/schema.json", diff --git a/docs/generated/packages/nest/generators/guard.json b/docs/generated/packages/nest/generators/guard.json index 93d3078b4c01c..30a4921bd1d3d 100644 --- a/docs/generated/packages/nest/generators/guard.json +++ b/docs/generated/packages/nest/generators/guard.json @@ -1,6 +1,6 @@ { "name": "guard", - "factory": "./src/generators/guard/guard", + "factory": "./src/generators/guard/guard#guardGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestGuardGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `guard` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/guard/guard.ts", + "implementation": "/packages/nest/src/generators/guard/guard#guardGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/guard/schema.json", diff --git a/docs/generated/packages/nest/generators/interceptor.json b/docs/generated/packages/nest/generators/interceptor.json index ef09c543ac7f7..e07adda448095 100644 --- a/docs/generated/packages/nest/generators/interceptor.json +++ b/docs/generated/packages/nest/generators/interceptor.json @@ -1,6 +1,6 @@ { "name": "interceptor", - "factory": "./src/generators/interceptor/interceptor", + "factory": "./src/generators/interceptor/interceptor#interceptorGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestInterceptorGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `interceptor` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/interceptor/interceptor.ts", + "implementation": "/packages/nest/src/generators/interceptor/interceptor#interceptorGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/interceptor/schema.json", diff --git a/docs/generated/packages/nest/generators/interface.json b/docs/generated/packages/nest/generators/interface.json index 5db0c6af5c8e2..a9c555b16cab2 100644 --- a/docs/generated/packages/nest/generators/interface.json +++ b/docs/generated/packages/nest/generators/interface.json @@ -1,6 +1,6 @@ { "name": "interface", - "factory": "./src/generators/interface/interface", + "factory": "./src/generators/interface/interface#interfaceGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestInterfaceGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -35,16 +40,17 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `interface` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/interface/interface.ts", + "implementation": "/packages/nest/src/generators/interface/interface#interfaceGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/interface/schema.json", diff --git a/docs/generated/packages/nest/generators/middleware.json b/docs/generated/packages/nest/generators/middleware.json index 2f8aca2c5275c..24bf7428aefcf 100644 --- a/docs/generated/packages/nest/generators/middleware.json +++ b/docs/generated/packages/nest/generators/middleware.json @@ -1,6 +1,6 @@ { "name": "middleware", - "factory": "./src/generators/middleware/middleware", + "factory": "./src/generators/middleware/middleware#middlewareGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestMiddlewareGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `middleware` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/middleware/middleware.ts", + "implementation": "/packages/nest/src/generators/middleware/middleware#middlewareGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/middleware/schema.json", diff --git a/docs/generated/packages/nest/generators/module.json b/docs/generated/packages/nest/generators/module.json index fcff5308bd138..4492a1e71f4ce 100644 --- a/docs/generated/packages/nest/generators/module.json +++ b/docs/generated/packages/nest/generators/module.json @@ -1,6 +1,6 @@ { "name": "module", - "factory": "./src/generators/module/module", + "factory": "./src/generators/module/module#moduleGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestModuleGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -35,6 +40,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -55,11 +61,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `module` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/module/module.ts", + "implementation": "/packages/nest/src/generators/module/module#moduleGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/module/schema.json", diff --git a/docs/generated/packages/nest/generators/pipe.json b/docs/generated/packages/nest/generators/pipe.json index 083af3a507e35..c57fc9195de2f 100644 --- a/docs/generated/packages/nest/generators/pipe.json +++ b/docs/generated/packages/nest/generators/pipe.json @@ -1,6 +1,6 @@ { "name": "pipe", - "factory": "./src/generators/pipe/pipe", + "factory": "./src/generators/pipe/pipe#pipeGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestPipeGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `pipe` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/pipe/pipe.ts", + "implementation": "/packages/nest/src/generators/pipe/pipe#pipeGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/pipe/schema.json", diff --git a/docs/generated/packages/nest/generators/provider.json b/docs/generated/packages/nest/generators/provider.json index 6b8efe3d3f587..6105d10b1b077 100644 --- a/docs/generated/packages/nest/generators/provider.json +++ b/docs/generated/packages/nest/generators/provider.json @@ -1,6 +1,6 @@ { "name": "provider", - "factory": "./src/generators/provider/provider", + "factory": "./src/generators/provider/provider#providerGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestProviderGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `provider` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/provider/provider.ts", + "implementation": "/packages/nest/src/generators/provider/provider#providerGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/provider/schema.json", diff --git a/docs/generated/packages/nest/generators/resolver.json b/docs/generated/packages/nest/generators/resolver.json index 0b78e74b6d63f..fd991a0c826b3 100644 --- a/docs/generated/packages/nest/generators/resolver.json +++ b/docs/generated/packages/nest/generators/resolver.json @@ -1,6 +1,6 @@ { "name": "resolver", - "factory": "./src/generators/resolver/resolver", + "factory": "./src/generators/resolver/resolver#resolverGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestResolverGenerator", @@ -20,10 +20,10 @@ "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +41,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -51,11 +52,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `resolver` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/resolver/resolver.ts", + "implementation": "/packages/nest/src/generators/resolver/resolver#resolverGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/resolver/schema.json", diff --git a/docs/generated/packages/nest/generators/resource.json b/docs/generated/packages/nest/generators/resource.json index fb8efe36ddc74..a7339511bbdd0 100644 --- a/docs/generated/packages/nest/generators/resource.json +++ b/docs/generated/packages/nest/generators/resource.json @@ -1,6 +1,6 @@ { "name": "resource", - "factory": "./src/generators/resource/resource", + "factory": "./src/generators/resource/resource#resourceGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestResourceGenerator", @@ -20,10 +20,10 @@ "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +41,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -91,11 +92,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `resource` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/resource/resource.ts", + "implementation": "/packages/nest/src/generators/resource/resource#resourceGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/resource/schema.json", diff --git a/docs/generated/packages/nest/generators/service.json b/docs/generated/packages/nest/generators/service.json index ee4a4011f9a04..7159a9a15f5de 100644 --- a/docs/generated/packages/nest/generators/service.json +++ b/docs/generated/packages/nest/generators/service.json @@ -1,6 +1,6 @@ { "name": "service", - "factory": "./src/generators/service/service", + "factory": "./src/generators/service/service#serviceGeneratorInternal", "schema": { "$schema": "http://json-schema.org/schema", "$id": "NxNestServiceGenerator", @@ -15,15 +15,20 @@ "$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"] + }, "project": { "description": "The Nest project to target.", "type": "string", "$default": { "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -41,6 +46,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -51,11 +57,11 @@ } }, "additionalProperties": false, - "required": ["name", "project"], + "required": ["name"], "presets": [] }, "description": "Run the `service` NestJS generator with Nx project support.", - "implementation": "/packages/nest/src/generators/service/service.ts", + "implementation": "/packages/nest/src/generators/service/service#serviceGeneratorInternal.ts", "aliases": [], "hidden": false, "path": "/packages/nest/src/generators/service/schema.json", diff --git a/packages/nest/generators.json b/packages/nest/generators.json index f7a242d051584..bac206b970376 100644 --- a/packages/nest/generators.json +++ b/packages/nest/generators.json @@ -25,77 +25,77 @@ "description": "Create a new NestJS library." }, "class": { - "factory": "./src/generators/class/class", + "factory": "./src/generators/class/class#classGeneratorInternal", "schema": "./src/generators/class/schema.json", "description": "Run the `class` NestJS generator with Nx project support." }, "controller": { - "factory": "./src/generators/controller/controller", + "factory": "./src/generators/controller/controller#controllerGeneratorInternal", "schema": "./src/generators/controller/schema.json", "description": "Run the `controller` NestJS generator with Nx project support." }, "decorator": { - "factory": "./src/generators/decorator/decorator", + "factory": "./src/generators/decorator/decorator#decoratorGeneratorInternal", "schema": "./src/generators/decorator/schema.json", "description": "Run the `decorator` NestJS generator with Nx project support." }, "filter": { - "factory": "./src/generators/filter/filter", + "factory": "./src/generators/filter/filter#filterGeneratorInternal", "schema": "./src/generators/filter/schema.json", "description": "Run the `filter` NestJS generator with Nx project support." }, "gateway": { - "factory": "./src/generators/gateway/gateway", + "factory": "./src/generators/gateway/gateway#gatewayGeneratorInternal", "schema": "./src/generators/gateway/schema.json", "description": "Run the `gateway` NestJS generator with Nx project support." }, "guard": { - "factory": "./src/generators/guard/guard", + "factory": "./src/generators/guard/guard#guardGeneratorInternal", "schema": "./src/generators/guard/schema.json", "description": "Run the `guard` NestJS generator with Nx project support." }, "interceptor": { - "factory": "./src/generators/interceptor/interceptor", + "factory": "./src/generators/interceptor/interceptor#interceptorGeneratorInternal", "schema": "./src/generators/interceptor/schema.json", "description": "Run the `interceptor` NestJS generator with Nx project support." }, "interface": { - "factory": "./src/generators/interface/interface", + "factory": "./src/generators/interface/interface#interfaceGeneratorInternal", "schema": "./src/generators/interface/schema.json", "description": "Run the `interface` NestJS generator with Nx project support." }, "middleware": { - "factory": "./src/generators/middleware/middleware", + "factory": "./src/generators/middleware/middleware#middlewareGeneratorInternal", "schema": "./src/generators/middleware/schema.json", "description": "Run the `middleware` NestJS generator with Nx project support." }, "module": { - "factory": "./src/generators/module/module", + "factory": "./src/generators/module/module#moduleGeneratorInternal", "schema": "./src/generators/module/schema.json", "description": "Run the `module` NestJS generator with Nx project support." }, "pipe": { - "factory": "./src/generators/pipe/pipe", + "factory": "./src/generators/pipe/pipe#pipeGeneratorInternal", "schema": "./src/generators/pipe/schema.json", "description": "Run the `pipe` NestJS generator with Nx project support." }, "provider": { - "factory": "./src/generators/provider/provider", + "factory": "./src/generators/provider/provider#providerGeneratorInternal", "schema": "./src/generators/provider/schema.json", "description": "Run the `provider` NestJS generator with Nx project support." }, "resolver": { - "factory": "./src/generators/resolver/resolver", + "factory": "./src/generators/resolver/resolver#resolverGeneratorInternal", "schema": "./src/generators/resolver/schema.json", "description": "Run the `resolver` NestJS generator with Nx project support." }, "resource": { - "factory": "./src/generators/resource/resource", + "factory": "./src/generators/resource/resource#resourceGeneratorInternal", "schema": "./src/generators/resource/schema.json", "description": "Run the `resource` NestJS generator with Nx project support." }, "service": { - "factory": "./src/generators/service/service", + "factory": "./src/generators/service/service#serviceGeneratorInternal", "schema": "./src/generators/service/schema.json", "description": "Run the `service` NestJS generator with Nx project support." } diff --git a/packages/nest/src/generators/class/class.ts b/packages/nest/src/generators/class/class.ts index c8f16c0a6875c..bc9bd78b32f23 100644 --- a/packages/nest/src/generators/class/class.ts +++ b/packages/nest/src/generators/class/class.ts @@ -13,23 +13,39 @@ import { export type ClassGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function classGenerator( +export async function classGenerator( + tree: Tree, + rawOptions: ClassGeneratorOptions +) { + await classGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function classGeneratorInternal( tree: Tree, rawOptions: ClassGeneratorOptions ): Promise { - const options = normalizeClassOptions(tree, rawOptions); + const options = await normalizeClassOptions(tree, rawOptions); return runNestSchematic(tree, 'class', options); } export default classGenerator; -function normalizeClassOptions( +async function normalizeClassOptions( tree: Tree, options: ClassGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'class', + '@nx/nest:class', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/class/schema.json b/packages/nest/src/generators/class/schema.json index 5bb836a2020df..87458480dbad7 100644 --- a/packages/nest/src/generators/class/schema.json +++ b/packages/nest/src/generators/class/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/controller/controller.ts b/packages/nest/src/generators/controller/controller.ts index d8e9487a85cf8..e668e5016eda5 100644 --- a/packages/nest/src/generators/controller/controller.ts +++ b/packages/nest/src/generators/controller/controller.ts @@ -16,23 +16,39 @@ export type ControllerGeneratorOptions = NestGeneratorWithLanguageOption & skipImport?: boolean; }; -export function controllerGenerator( +export async function controllerGenerator( + tree: Tree, + rawOptions: ControllerGeneratorOptions +) { + await controllerGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function controllerGeneratorInternal( tree: Tree, rawOptions: ControllerGeneratorOptions ): Promise { - const options = normalizeControllerOptions(tree, rawOptions); + const options = await normalizeControllerOptions(tree, rawOptions); return runNestSchematic(tree, 'controller', options); } export default controllerGenerator; -function normalizeControllerOptions( +async function normalizeControllerOptions( tree: Tree, options: ControllerGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'controller', + '@nx/nest:controller', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, module: options.module, skipImport: options.skipImport, diff --git a/packages/nest/src/generators/controller/schema.json b/packages/nest/src/generators/controller/schema.json index 4c7755eaf11d0..8ed853cddb3bd 100644 --- a/packages/nest/src/generators/controller/schema.json +++ b/packages/nest/src/generators/controller/schema.json @@ -22,10 +22,15 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." + }, + "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"] }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -62,5 +68,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/decorator/decorator.ts b/packages/nest/src/generators/decorator/decorator.ts index 1879890ff84f5..185a11144ec31 100644 --- a/packages/nest/src/generators/decorator/decorator.ts +++ b/packages/nest/src/generators/decorator/decorator.ts @@ -7,23 +7,39 @@ import { normalizeOptions, runNestSchematic } from '../utils'; export type DecoratorGeneratorOptions = NestGeneratorWithLanguageOption; -export function decoratorGenerator( +export async function decoratorGenerator( + tree: Tree, + rawOptions: DecoratorGeneratorOptions +) { + await decoratorGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function decoratorGeneratorInternal( tree: Tree, rawOptions: DecoratorGeneratorOptions ): Promise { - const options = normalizeDecoratorOptions(tree, rawOptions); + const options = await normalizeDecoratorOptions(tree, rawOptions); return runNestSchematic(tree, 'decorator', options); } export default decoratorGenerator; -function normalizeDecoratorOptions( +async function normalizeDecoratorOptions( tree: Tree, options: DecoratorGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'decorator', + '@nx/nest:decorator', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, }; } diff --git a/packages/nest/src/generators/decorator/schema.json b/packages/nest/src/generators/decorator/schema.json index 904046786ed1c..f49641838980e 100644 --- a/packages/nest/src/generators/decorator/schema.json +++ b/packages/nest/src/generators/decorator/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -37,6 +42,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -47,5 +53,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/filter/filter.ts b/packages/nest/src/generators/filter/filter.ts index 4ff229beb6cec..88f466a71c8ca 100644 --- a/packages/nest/src/generators/filter/filter.ts +++ b/packages/nest/src/generators/filter/filter.ts @@ -13,23 +13,39 @@ import { export type FilterGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function filterGenerator( +export async function filterGenerator( + tree: Tree, + rawOptions: FilterGeneratorOptions +) { + await filterGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function filterGeneratorInternal( tree: Tree, rawOptions: FilterGeneratorOptions ): Promise { - const options = normalizeFilterOptions(tree, rawOptions); + const options = await normalizeFilterOptions(tree, rawOptions); return runNestSchematic(tree, 'filter', options); } export default filterGenerator; -function normalizeFilterOptions( +async function normalizeFilterOptions( tree: Tree, options: FilterGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'filter', + '@nx/nest:filter', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/filter/schema.json b/packages/nest/src/generators/filter/schema.json index f390e55cfc4e4..3f78011872399 100644 --- a/packages/nest/src/generators/filter/schema.json +++ b/packages/nest/src/generators/filter/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/gateway/gateway.ts b/packages/nest/src/generators/gateway/gateway.ts index cc10b0b88b375..3236a368577a7 100644 --- a/packages/nest/src/generators/gateway/gateway.ts +++ b/packages/nest/src/generators/gateway/gateway.ts @@ -13,23 +13,39 @@ import { export type GatewayGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function gatewayGenerator( +export async function gatewayGenerator( + tree: Tree, + rawOptions: GatewayGeneratorOptions +) { + await gatewayGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function gatewayGeneratorInternal( tree: Tree, rawOptions: GatewayGeneratorOptions ): Promise { - const options = normalizeGatewayOptions(tree, rawOptions); + const options = await normalizeGatewayOptions(tree, rawOptions); return runNestSchematic(tree, 'gateway', options); } export default gatewayGenerator; -function normalizeGatewayOptions( +async function normalizeGatewayOptions( tree: Tree, options: GatewayGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'gateway', + '@nx/nest:gateway', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/gateway/schema.json b/packages/nest/src/generators/gateway/schema.json index fae2d5426a299..385eb04badab1 100644 --- a/packages/nest/src/generators/gateway/schema.json +++ b/packages/nest/src/generators/gateway/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/guard/guard.ts b/packages/nest/src/generators/guard/guard.ts index 80b36cb0f88dc..dea986bf55508 100644 --- a/packages/nest/src/generators/guard/guard.ts +++ b/packages/nest/src/generators/guard/guard.ts @@ -13,23 +13,39 @@ import { export type GuardGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function guardGenerator( +export async function guardGenerator( + tree: Tree, + rawOptions: GuardGeneratorOptions +) { + await guardGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function guardGeneratorInternal( tree: Tree, rawOptions: GuardGeneratorOptions ): Promise { - const options = normalizeGuardOptions(tree, rawOptions); + const options = await normalizeGuardOptions(tree, rawOptions); return runNestSchematic(tree, 'guard', options); } export default guardGenerator; -function normalizeGuardOptions( +async function normalizeGuardOptions( tree: Tree, options: GuardGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'guard', + '@nx/nest:guard', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/guard/schema.json b/packages/nest/src/generators/guard/schema.json index 76199767da50a..5b27d767a5ad8 100644 --- a/packages/nest/src/generators/guard/schema.json +++ b/packages/nest/src/generators/guard/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/interceptor/interceptor.ts b/packages/nest/src/generators/interceptor/interceptor.ts index a1387f34450c1..787f99c0ecd4f 100644 --- a/packages/nest/src/generators/interceptor/interceptor.ts +++ b/packages/nest/src/generators/interceptor/interceptor.ts @@ -13,23 +13,39 @@ import { export type InterceptorGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function interceptorGenerator( +export async function interceptorGenerator( + tree: Tree, + rawOptions: InterceptorGeneratorOptions +) { + await interceptorGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function interceptorGeneratorInternal( tree: Tree, rawOptions: InterceptorGeneratorOptions ): Promise { - const options = normalizeInterceptorOptions(tree, rawOptions); + const options = await normalizeInterceptorOptions(tree, rawOptions); return runNestSchematic(tree, 'interceptor', options); } export default interceptorGenerator; -function normalizeInterceptorOptions( +async function normalizeInterceptorOptions( tree: Tree, options: InterceptorGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'interceptor', + '@nx/nest:interceptor', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/interceptor/schema.json b/packages/nest/src/generators/interceptor/schema.json index 446de1eefce4b..90b39a76aff45 100644 --- a/packages/nest/src/generators/interceptor/schema.json +++ b/packages/nest/src/generators/interceptor/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/interface/interface.ts b/packages/nest/src/generators/interface/interface.ts index b3ec2f50a529f..dd11381ab26f9 100644 --- a/packages/nest/src/generators/interface/interface.ts +++ b/packages/nest/src/generators/interface/interface.ts @@ -4,11 +4,26 @@ import { normalizeOptions, runNestSchematic } from '../utils'; export type InterfaceGeneratorOptions = NestGeneratorOptions; -export function interfaceGenerator( +export async function interfaceGenerator( + tree: Tree, + rawOptions: InterfaceGeneratorOptions +) { + await interfaceGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function interfaceGeneratorInternal( tree: Tree, rawOptions: InterfaceGeneratorOptions ): Promise { - const options = normalizeOptions(tree, rawOptions); + const options = await normalizeOptions( + tree, + 'interface', + '@nx/nest:interface', + rawOptions + ); return runNestSchematic(tree, 'interface', options); } diff --git a/packages/nest/src/generators/interface/schema.json b/packages/nest/src/generators/interface/schema.json index 7dee7e8b4af96..b6e4682eb337c 100644 --- a/packages/nest/src/generators/interface/schema.json +++ b/packages/nest/src/generators/interface/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -37,10 +42,11 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/middleware/middleware.ts b/packages/nest/src/generators/middleware/middleware.ts index 3b42bbfa6b724..b4570e550bbc9 100644 --- a/packages/nest/src/generators/middleware/middleware.ts +++ b/packages/nest/src/generators/middleware/middleware.ts @@ -13,23 +13,39 @@ import { export type MiddlewareGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function middlewareGenerator( +export async function middlewareGenerator( + tree: Tree, + rawOptions: MiddlewareGeneratorOptions +) { + await middlewareGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function middlewareGeneratorInternal( tree: Tree, rawOptions: MiddlewareGeneratorOptions ): Promise { - const options = normalizeMiddlewareOptions(tree, rawOptions); + const options = await normalizeMiddlewareOptions(tree, rawOptions); return runNestSchematic(tree, 'middleware', options); } export default middlewareGenerator; -function normalizeMiddlewareOptions( +async function normalizeMiddlewareOptions( tree: Tree, options: MiddlewareGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'middleware', + '@nx/nest:middleware', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/middleware/schema.json b/packages/nest/src/generators/middleware/schema.json index 471c730ecd936..1989aa36cefe4 100644 --- a/packages/nest/src/generators/middleware/schema.json +++ b/packages/nest/src/generators/middleware/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/module/module.ts b/packages/nest/src/generators/module/module.ts index c29a9a41a44fb..e2df7a9cb6b5c 100644 --- a/packages/nest/src/generators/module/module.ts +++ b/packages/nest/src/generators/module/module.ts @@ -10,23 +10,39 @@ export type ModuleGeneratorOptions = NestGeneratorWithLanguageOption & { skipImport?: boolean; }; -export function moduleGenerator( +export async function moduleGenerator( + tree: Tree, + rawOptions: ModuleGeneratorOptions +) { + await moduleGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function moduleGeneratorInternal( tree: Tree, rawOptions: ModuleGeneratorOptions ): Promise { - const options = normalizeModuleOptions(tree, rawOptions); + const options = await normalizeModuleOptions(tree, rawOptions); return runNestSchematic(tree, 'module', options); } export default moduleGenerator; -function normalizeModuleOptions( +async function normalizeModuleOptions( tree: Tree, options: ModuleGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOption = await normalizeOptions( + tree, + 'module', + '@nx/nest:module', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOption, language: options.language, module: options.module, skipImport: options.skipImport, diff --git a/packages/nest/src/generators/module/schema.json b/packages/nest/src/generators/module/schema.json index 98568736d103a..d1f8a57ff9a20 100644 --- a/packages/nest/src/generators/module/schema.json +++ b/packages/nest/src/generators/module/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -37,6 +42,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -57,5 +63,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/pipe/pipe.ts b/packages/nest/src/generators/pipe/pipe.ts index 28ea67d3efdcb..0461e3b6ef137 100644 --- a/packages/nest/src/generators/pipe/pipe.ts +++ b/packages/nest/src/generators/pipe/pipe.ts @@ -13,23 +13,39 @@ import { export type PipeGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function pipeGenerator( +export async function pipeGenerator( + tree: Tree, + rawOptions: PipeGeneratorOptions +) { + await pipeGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function pipeGeneratorInternal( tree: Tree, rawOptions: PipeGeneratorOptions ): Promise { - const options = normalizePipeOptions(tree, rawOptions); + const options = await normalizePipeOptions(tree, rawOptions); return runNestSchematic(tree, 'pipe', options); } export default pipeGenerator; -function normalizePipeOptions( +async function normalizePipeOptions( tree: Tree, options: PipeGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'pipe', + '@nx/nest:pipe', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/pipe/schema.json b/packages/nest/src/generators/pipe/schema.json index 02de60fbb6be0..c7543b81f4d73 100644 --- a/packages/nest/src/generators/pipe/schema.json +++ b/packages/nest/src/generators/pipe/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/provider/provider.ts b/packages/nest/src/generators/provider/provider.ts index c708dea83bda5..0b086a27634f9 100644 --- a/packages/nest/src/generators/provider/provider.ts +++ b/packages/nest/src/generators/provider/provider.ts @@ -13,23 +13,39 @@ import { export type ProviderGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function providerGenerator( +export async function providerGenerator( + tree: Tree, + rawOptions: ProviderGeneratorOptions +) { + await providerGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function providerGeneratorInternal( tree: Tree, rawOptions: ProviderGeneratorOptions ): Promise { - const options = normalizeProviderOptions(tree, rawOptions); + const options = await normalizeProviderOptions(tree, rawOptions); return runNestSchematic(tree, 'provider', options); } export default providerGenerator; -function normalizeProviderOptions( +async function normalizeProviderOptions( tree: Tree, options: ProviderGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'provider', + '@nx/nest:provider', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/provider/schema.json b/packages/nest/src/generators/provider/schema.json index 4f217c29aadf1..98c582ac3a143 100644 --- a/packages/nest/src/generators/provider/schema.json +++ b/packages/nest/src/generators/provider/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": true }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/resolver/resolver.ts b/packages/nest/src/generators/resolver/resolver.ts index 06e86c708f3c8..2c8a86f298f9d 100644 --- a/packages/nest/src/generators/resolver/resolver.ts +++ b/packages/nest/src/generators/resolver/resolver.ts @@ -13,23 +13,39 @@ import { export type ResolverGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function resolverGenerator( +export async function resolverGenerator( + tree: Tree, + rawOptions: ResolverGeneratorOptions +) { + await resolverGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function resolverGeneratorInternal( tree: Tree, rawOptions: ResolverGeneratorOptions ): Promise { - const options = normalizeResolverOptions(tree, rawOptions); + const options = await normalizeResolverOptions(tree, rawOptions); return runNestSchematic(tree, 'resolver', options); } export default resolverGenerator; -function normalizeResolverOptions( +async function normalizeResolverOptions( tree: Tree, options: ResolverGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'resolver', + '@nx/nest:resolver', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/resolver/schema.json b/packages/nest/src/generators/resolver/schema.json index 546cd16931da2..cb72b32525000 100644 --- a/packages/nest/src/generators/resolver/schema.json +++ b/packages/nest/src/generators/resolver/schema.json @@ -22,10 +22,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +43,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -53,5 +54,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/resource/resource.ts b/packages/nest/src/generators/resource/resource.ts index f5aa0faf9cba2..cd4f44e4fab4e 100644 --- a/packages/nest/src/generators/resource/resource.ts +++ b/packages/nest/src/generators/resource/resource.ts @@ -15,23 +15,39 @@ export type ResourceGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption & NestGeneratorWithResourceOption; -export function resourceGenerator( +export async function resourceGenerator( + tree: Tree, + rawOptions: ResourceGeneratorOptions +) { + await resourceGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function resourceGeneratorInternal( tree: Tree, rawOptions: ResourceGeneratorOptions ): Promise { - const options = normalizeResourceOptions(tree, rawOptions); + const options = await normalizeResourceOptions(tree, rawOptions); return runNestSchematic(tree, 'resource', options); } export default resourceGenerator; -function normalizeResourceOptions( +async function normalizeResourceOptions( tree: Tree, options: ResourceGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'resource', + '@nx/nest:resource', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/resource/schema.json b/packages/nest/src/generators/resource/schema.json index 2b2f4ca6bbdb0..40dcab2c03f48 100644 --- a/packages/nest/src/generators/resource/schema.json +++ b/packages/nest/src/generators/resource/schema.json @@ -22,10 +22,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +43,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -102,5 +103,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/service/schema.json b/packages/nest/src/generators/service/schema.json index 878d9e59a5613..0c2832aad801c 100644 --- a/packages/nest/src/generators/service/schema.json +++ b/packages/nest/src/generators/service/schema.json @@ -15,6 +15,11 @@ }, "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"] + }, "project": { "description": "The Nest project to target.", "type": "string", @@ -22,10 +27,10 @@ "$source": "projectName" }, "alias": "p", - "x-prompt": "What Nest project would you like to target?" + "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." }, "directory": { - "description": "Directory where the generated files are placed.", + "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.", "type": "string", "aliases": ["dir", "path"] }, @@ -43,6 +48,7 @@ }, "flat": { "description": "Flag to indicate if a directory is created.", + "x-deprecated": "provide the `directory` option instead and use the `as-provided` format. it will be removed in nx v18.", "type": "boolean", "default": false }, @@ -53,5 +59,5 @@ } }, "additionalProperties": false, - "required": ["name", "project"] + "required": ["name"] } diff --git a/packages/nest/src/generators/service/service.ts b/packages/nest/src/generators/service/service.ts index 6a7011cfe0719..573d8ff5f9e7c 100644 --- a/packages/nest/src/generators/service/service.ts +++ b/packages/nest/src/generators/service/service.ts @@ -13,23 +13,39 @@ import { export type ServiceGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption; -export function serviceGenerator( +export async function serviceGenerator( + tree: Tree, + rawOptions: ServiceGeneratorOptions +) { + await serviceGeneratorInternal(tree, { + nameAndDirectoryFormat: 'derived', + ...rawOptions, + }); +} + +export async function serviceGeneratorInternal( tree: Tree, rawOptions: ServiceGeneratorOptions ): Promise { - const options = normalizeServiceOptions(tree, rawOptions); + const options = await normalizeServiceOptions(tree, rawOptions); return runNestSchematic(tree, 'service', options); } export default serviceGenerator; -function normalizeServiceOptions( +async function normalizeServiceOptions( tree: Tree, options: ServiceGeneratorOptions -): NormalizedOptions { +): Promise { + const normalizedOptions = await normalizeOptions( + tree, + 'service', + '@nx/nest:service', + options + ); return { - ...normalizeOptions(tree, options), + ...normalizedOptions, language: options.language, spec: unitTestRunnerToSpec(options.unitTestRunner), }; diff --git a/packages/nest/src/generators/utils/normalize-options.ts b/packages/nest/src/generators/utils/normalize-options.ts index 42fdcbba5b87a..1fd22bfc43c14 100644 --- a/packages/nest/src/generators/utils/normalize-options.ts +++ b/packages/nest/src/generators/utils/normalize-options.ts @@ -1,27 +1,36 @@ import type { Tree } from '@nx/devkit'; -import { names, readProjectConfiguration } from '@nx/devkit'; import type { NestGeneratorOptions, NormalizedOptions, UnitTestRunner, } from './types'; +import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils'; -export function normalizeOptions( +export async function normalizeOptions( tree: Tree, + artifactType: string, + callingGenerator: string, options: NestGeneratorOptions -): NormalizedOptions { - const { sourceRoot } = readProjectConfiguration(tree, options.project); +): Promise { + const { directory, fileName } = + await determineArtifactNameAndDirectoryOptions(tree, { + callingGenerator, + artifactType, + name: options.name, + directory: options.directory, + project: options.project, + flat: options.flat, + derivedDirectory: options.directory, + nameAndDirectoryFormat: options.nameAndDirectoryFormat, + }); - const normalizedOptions: NormalizedOptions = { + return { ...options, - flat: options.flat, - name: names(options.name).fileName, - path: options.directory, + flat: true, + name: fileName, skipFormat: options.skipFormat, - sourceRoot, + sourceRoot: directory, }; - - return normalizedOptions; } export function unitTestRunnerToSpec( diff --git a/packages/nest/src/generators/utils/types.ts b/packages/nest/src/generators/utils/types.ts index 03ae3f19330dc..d4d23c93290c3 100644 --- a/packages/nest/src/generators/utils/types.ts +++ b/packages/nest/src/generators/utils/types.ts @@ -1,3 +1,5 @@ +import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils'; + export type Language = 'js' | 'ts'; export type UnitTestRunner = 'jest' | 'none'; export type NestSchematic = @@ -29,6 +31,7 @@ export type NestGeneratorOptions = { directory?: string; flat?: boolean; skipFormat?: boolean; + nameAndDirectoryFormat?: NameAndDirectoryFormat; }; export type NestGeneratorWithLanguageOption = NestGeneratorOptions & {