feat(node): add nestjs support to node app plugin (#15484)

This commit is contained in:
Nicholas Cunningham 2023-03-08 09:42:09 -07:00 committed by GitHub
parent 216b961be9
commit 79f5fc3108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 13 deletions

View File

@ -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"

View File

@ -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,

View File

@ -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.",

View File

@ -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/]',
},
];

View File

@ -16,7 +16,9 @@ export function normalizeOptions(
? `${names(projectDirectory).fileName}/${names(options.name).fileName}`
: names(options.name).fileName;
const appProjectRoot = joinPathFragments(
const appProjectRoot = options.rootProject
? '.'
: joinPathFragments(
layoutDirectory ?? getWorkspaceLayout(tree).appsDir,
appDirectory
);
@ -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
};
}

View File

@ -12,6 +12,7 @@ export interface ApplicationGeneratorOptions {
tags?: string;
unitTestRunner?: UnitTestRunner;
setParserOptionsProject?: boolean;
rootProject?: boolean;
}
interface NormalizedOptions extends ApplicationGeneratorOptions {

View File

@ -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, {

View File

@ -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,

View File

@ -22,4 +22,4 @@ export interface Schema {
docker?: boolean;
}
export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'none';
export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';

View File

@ -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"

View File

@ -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

View File

@ -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.",