diff --git a/docs/generated/packages/node/generators/application.json b/docs/generated/packages/node/generators/application.json index 968ae53104..a2bbe09416 100644 --- a/docs/generated/packages/node/generators/application.json +++ b/docs/generated/packages/node/generators/application.json @@ -91,7 +91,7 @@ "framework": { "description": "Generate the node application using a framework", "type": "string", - "enum": ["express", "fastify", "koa", "none"], + "enum": ["express", "fastify", "koa", "nest", "none"], "default": "none", "x-prompt": "Which framework do you want to use?", "x-priority": "important" diff --git a/docs/generated/packages/workspace/generators/new.json b/docs/generated/packages/workspace/generators/new.json index c13838b194..ad4605cca4 100644 --- a/docs/generated/packages/workspace/generators/new.json +++ b/docs/generated/packages/workspace/generators/new.json @@ -67,7 +67,7 @@ "framework": { "description": "The framework which the application is using", "type": "string", - "enum": ["express", "koa", "fastify", "connect"] + "enum": ["express", "koa", "fastify", "nest", "none"] } }, "additionalProperties": true, diff --git a/docs/generated/packages/workspace/generators/preset.json b/docs/generated/packages/workspace/generators/preset.json index 0dc258c1dd..56094af138 100644 --- a/docs/generated/packages/workspace/generators/preset.json +++ b/docs/generated/packages/workspace/generators/preset.json @@ -72,7 +72,7 @@ "framework": { "description": "The framework which the application is using", "type": "string", - "enum": ["express", "koa", "fastify", "connect"] + "enum": ["express", "koa", "fastify", "nest", "none"] }, "bundler": { "description": "The bundler to use for building the application.", diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index 8837fb2026..5cc802d6b7 100644 --- a/packages/create-nx-workspace/bin/create-nx-workspace.ts +++ b/packages/create-nx-workspace/bin/create-nx-workspace.ts @@ -731,11 +731,15 @@ async function determineFramework( }, { name: 'fastify', - message: 'fastify [https://www.fastify.io/]', + message: 'Fastify [https://www.fastify.io/]', }, { name: 'koa', - message: 'koa [https://koajs.com/]', + message: 'Koa [https://koajs.com/]', + }, + { + name: 'nest', + message: 'NestJs [https://nestjs.com/]', }, ]; diff --git a/packages/nest/src/generators/application/lib/normalize-options.ts b/packages/nest/src/generators/application/lib/normalize-options.ts index 6175739e66..c469de1adb 100644 --- a/packages/nest/src/generators/application/lib/normalize-options.ts +++ b/packages/nest/src/generators/application/lib/normalize-options.ts @@ -16,10 +16,12 @@ export function normalizeOptions( ? `${names(projectDirectory).fileName}/${names(options.name).fileName}` : names(options.name).fileName; - const appProjectRoot = joinPathFragments( - layoutDirectory ?? getWorkspaceLayout(tree).appsDir, - appDirectory - ); + const appProjectRoot = options.rootProject + ? '.' + : joinPathFragments( + layoutDirectory ?? getWorkspaceLayout(tree).appsDir, + appDirectory + ); return { ...options, @@ -43,6 +45,7 @@ export function toNodeApplicationGeneratorOptions( tags: options.tags, unitTestRunner: options.unitTestRunner, setParserOptionsProject: options.setParserOptionsProject, + rootProject: options.rootProject, bundler: 'webpack', // Some features require webpack plugins such as TS transformers }; } diff --git a/packages/nest/src/generators/application/schema.d.ts b/packages/nest/src/generators/application/schema.d.ts index aa84089021..e71c288ef7 100644 --- a/packages/nest/src/generators/application/schema.d.ts +++ b/packages/nest/src/generators/application/schema.d.ts @@ -12,6 +12,7 @@ export interface ApplicationGeneratorOptions { tags?: string; unitTestRunner?: UnitTestRunner; setParserOptionsProject?: boolean; + rootProject?: boolean; } interface NormalizedOptions extends ApplicationGeneratorOptions { diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index aa00bd216b..6a58d3ade1 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -464,6 +464,7 @@ describe('app', () => { ['fastify' as const, true], ['express' as const, false], ['koa' as const, false], + ['nest' as const, false], ])('--unitTestRunner', (framework, checkSpecFile) => { it('should generate test target and spec file by default', async () => { await applicationGenerator(tree, { diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index 7843d351ac..f98655d65e 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -2,6 +2,7 @@ import { addDependenciesToPackageJson, addProjectConfiguration, convertNxGenerator, + ensurePackage, extractLayoutDirectory, formatFiles, generateFiles, @@ -353,6 +354,11 @@ export async function applicationGenerator(tree: Tree, schema: Schema) { const options = normalizeOptions(tree, schema); const tasks: GeneratorCallback[] = []; + if (options.framework === 'nest') { + const { applicationGenerator } = ensurePackage('@nrwl/nest', nxVersion); + return await applicationGenerator(tree, options); + } + const initTask = await initGenerator(tree, { ...schema, skipFormat: true, diff --git a/packages/node/src/generators/application/schema.d.ts b/packages/node/src/generators/application/schema.d.ts index 2503ef9016..e46e3ebceb 100644 --- a/packages/node/src/generators/application/schema.d.ts +++ b/packages/node/src/generators/application/schema.d.ts @@ -22,4 +22,4 @@ export interface Schema { docker?: boolean; } -export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'none'; +export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none'; diff --git a/packages/node/src/generators/application/schema.json b/packages/node/src/generators/application/schema.json index f908e20e12..92b9f48010 100644 --- a/packages/node/src/generators/application/schema.json +++ b/packages/node/src/generators/application/schema.json @@ -91,7 +91,7 @@ "framework": { "description": "Generate the node application using a framework", "type": "string", - "enum": ["express", "fastify", "koa", "none"], + "enum": ["express", "fastify", "koa", "nest", "none"], "default": "none", "x-prompt": "Which framework do you want to use?", "x-priority": "important" diff --git a/packages/workspace/src/generators/new/schema.json b/packages/workspace/src/generators/new/schema.json index 9cbb90cb3e..b4e7c4c55a 100644 --- a/packages/workspace/src/generators/new/schema.json +++ b/packages/workspace/src/generators/new/schema.json @@ -70,7 +70,7 @@ "framework": { "description": "The framework which the application is using", "type": "string", - "enum": ["express", "koa", "fastify", "connect"] + "enum": ["express", "koa", "fastify", "nest", "none"] } }, "additionalProperties": true diff --git a/packages/workspace/src/generators/preset/schema.json b/packages/workspace/src/generators/preset/schema.json index 00bae90eca..ca6f3c5830 100644 --- a/packages/workspace/src/generators/preset/schema.json +++ b/packages/workspace/src/generators/preset/schema.json @@ -75,7 +75,7 @@ "framework": { "description": "The framework which the application is using", "type": "string", - "enum": ["express", "koa", "fastify", "connect"] + "enum": ["express", "koa", "fastify", "nest", "none"] }, "bundler": { "description": "The bundler to use for building the application.",