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": { "framework": {
"description": "Generate the node application using a framework", "description": "Generate the node application using a framework",
"type": "string", "type": "string",
"enum": ["express", "fastify", "koa", "none"], "enum": ["express", "fastify", "koa", "nest", "none"],
"default": "none", "default": "none",
"x-prompt": "Which framework do you want to use?", "x-prompt": "Which framework do you want to use?",
"x-priority": "important" "x-priority": "important"

View File

@ -67,7 +67,7 @@
"framework": { "framework": {
"description": "The framework which the application is using", "description": "The framework which the application is using",
"type": "string", "type": "string",
"enum": ["express", "koa", "fastify", "connect"] "enum": ["express", "koa", "fastify", "nest", "none"]
} }
}, },
"additionalProperties": true, "additionalProperties": true,

View File

@ -72,7 +72,7 @@
"framework": { "framework": {
"description": "The framework which the application is using", "description": "The framework which the application is using",
"type": "string", "type": "string",
"enum": ["express", "koa", "fastify", "connect"] "enum": ["express", "koa", "fastify", "nest", "none"]
}, },
"bundler": { "bundler": {
"description": "The bundler to use for building the application.", "description": "The bundler to use for building the application.",

View File

@ -731,11 +731,15 @@ async function determineFramework(
}, },
{ {
name: 'fastify', name: 'fastify',
message: 'fastify [https://www.fastify.io/]', message: 'Fastify [https://www.fastify.io/]',
}, },
{ {
name: 'koa', name: 'koa',
message: 'koa [https://koajs.com/]', message: 'Koa [https://koajs.com/]',
},
{
name: 'nest',
message: 'NestJs [https://nestjs.com/]',
}, },
]; ];

View File

@ -16,10 +16,12 @@ export function normalizeOptions(
? `${names(projectDirectory).fileName}/${names(options.name).fileName}` ? `${names(projectDirectory).fileName}/${names(options.name).fileName}`
: names(options.name).fileName; : names(options.name).fileName;
const appProjectRoot = joinPathFragments( const appProjectRoot = options.rootProject
layoutDirectory ?? getWorkspaceLayout(tree).appsDir, ? '.'
appDirectory : joinPathFragments(
); layoutDirectory ?? getWorkspaceLayout(tree).appsDir,
appDirectory
);
return { return {
...options, ...options,
@ -43,6 +45,7 @@ export function toNodeApplicationGeneratorOptions(
tags: options.tags, tags: options.tags,
unitTestRunner: options.unitTestRunner, unitTestRunner: options.unitTestRunner,
setParserOptionsProject: options.setParserOptionsProject, setParserOptionsProject: options.setParserOptionsProject,
rootProject: options.rootProject,
bundler: 'webpack', // Some features require webpack plugins such as TS transformers bundler: 'webpack', // Some features require webpack plugins such as TS transformers
}; };
} }

View File

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

View File

@ -464,6 +464,7 @@ describe('app', () => {
['fastify' as const, true], ['fastify' as const, true],
['express' as const, false], ['express' as const, false],
['koa' as const, false], ['koa' as const, false],
['nest' as const, false],
])('--unitTestRunner', (framework, checkSpecFile) => { ])('--unitTestRunner', (framework, checkSpecFile) => {
it('should generate test target and spec file by default', async () => { it('should generate test target and spec file by default', async () => {
await applicationGenerator(tree, { await applicationGenerator(tree, {

View File

@ -2,6 +2,7 @@ import {
addDependenciesToPackageJson, addDependenciesToPackageJson,
addProjectConfiguration, addProjectConfiguration,
convertNxGenerator, convertNxGenerator,
ensurePackage,
extractLayoutDirectory, extractLayoutDirectory,
formatFiles, formatFiles,
generateFiles, generateFiles,
@ -353,6 +354,11 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
const options = normalizeOptions(tree, schema); const options = normalizeOptions(tree, schema);
const tasks: GeneratorCallback[] = []; const tasks: GeneratorCallback[] = [];
if (options.framework === 'nest') {
const { applicationGenerator } = ensurePackage('@nrwl/nest', nxVersion);
return await applicationGenerator(tree, options);
}
const initTask = await initGenerator(tree, { const initTask = await initGenerator(tree, {
...schema, ...schema,
skipFormat: true, skipFormat: true,

View File

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

View File

@ -91,7 +91,7 @@
"framework": { "framework": {
"description": "Generate the node application using a framework", "description": "Generate the node application using a framework",
"type": "string", "type": "string",
"enum": ["express", "fastify", "koa", "none"], "enum": ["express", "fastify", "koa", "nest", "none"],
"default": "none", "default": "none",
"x-prompt": "Which framework do you want to use?", "x-prompt": "Which framework do you want to use?",
"x-priority": "important" "x-priority": "important"

View File

@ -70,7 +70,7 @@
"framework": { "framework": {
"description": "The framework which the application is using", "description": "The framework which the application is using",
"type": "string", "type": "string",
"enum": ["express", "koa", "fastify", "connect"] "enum": ["express", "koa", "fastify", "nest", "none"]
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -75,7 +75,7 @@
"framework": { "framework": {
"description": "The framework which the application is using", "description": "The framework which the application is using",
"type": "string", "type": "string",
"enum": ["express", "koa", "fastify", "connect"] "enum": ["express", "koa", "fastify", "nest", "none"]
}, },
"bundler": { "bundler": {
"description": "The bundler to use for building the application.", "description": "The bundler to use for building the application.",