From 92c44535456b6e504b0c1e66ddf151de52e12b5e Mon Sep 17 00:00:00 2001 From: Tine Kondo Date: Sat, 22 Jun 2024 11:44:44 +0000 Subject: [PATCH] fix: fix `mvnw` or `gradlew` no longer generated when creating simple projects --- .../project/lib/generate-ktor-project.ts | 6 +- .../project/lib/generate-micronaut-project.ts | 6 +- .../project/lib/generate-quarkus-project.ts | 6 +- .../project/lib/generate-boot-project.ts | 64 +++++++++++++------ 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/packages/nx-ktor/src/generators/project/lib/generate-ktor-project.ts b/packages/nx-ktor/src/generators/project/lib/generate-ktor-project.ts index 6fe982dc..82e48aa0 100644 --- a/packages/nx-ktor/src/generators/project/lib/generate-ktor-project.ts +++ b/packages/nx-ktor/src/generators/project/lib/generate-ktor-project.ts @@ -50,7 +50,11 @@ export async function generateKtorProject( mode: execPermission, }); } - if (options.keepProjectLevelWrapper) { + if ( + (options.transformIntoMultiModule || + options.addToExistingParentModule) && + options.keepProjectLevelWrapper + ) { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); diff --git a/packages/nx-micronaut/src/generators/project/lib/generate-micronaut-project.ts b/packages/nx-micronaut/src/generators/project/lib/generate-micronaut-project.ts index f18e3f93..0736c078 100644 --- a/packages/nx-micronaut/src/generators/project/lib/generate-micronaut-project.ts +++ b/packages/nx-micronaut/src/generators/project/lib/generate-micronaut-project.ts @@ -46,7 +46,11 @@ export async function generateMicronautProject( mode: execPermission, }); } - if (options.keepProjectLevelWrapper) { + if ( + (options.transformIntoMultiModule || + options.addToExistingParentModule) && + options.keepProjectLevelWrapper + ) { tree.write(`${options.projectRoot}/${filePath}`, entryContent, { mode: execPermission, }); diff --git a/packages/nx-quarkus/src/generators/project/lib/generate-quarkus-project.ts b/packages/nx-quarkus/src/generators/project/lib/generate-quarkus-project.ts index b2eccb04..9a75bd01 100644 --- a/packages/nx-quarkus/src/generators/project/lib/generate-quarkus-project.ts +++ b/packages/nx-quarkus/src/generators/project/lib/generate-quarkus-project.ts @@ -41,7 +41,11 @@ export async function generateQuarkusProject( mode: execPermission, }); } - if (options.keepProjectLevelWrapper) { + if ( + (options.transformIntoMultiModule || + options.addToExistingParentModule) && + options.keepProjectLevelWrapper + ) { tree.write(`${options.projectRoot}/${filePath}`, entryContent, { mode: execPermission, }); diff --git a/packages/nx-spring-boot/src/generators/project/lib/generate-boot-project.ts b/packages/nx-spring-boot/src/generators/project/lib/generate-boot-project.ts index 1a8d072e..fa194f6e 100644 --- a/packages/nx-spring-boot/src/generators/project/lib/generate-boot-project.ts +++ b/packages/nx-spring-boot/src/generators/project/lib/generate-boot-project.ts @@ -1,4 +1,11 @@ -import { Tree, joinPathFragments, logger, names, stripIndents, workspaceRoot } from '@nx/devkit'; +import { + Tree, + joinPathFragments, + logger, + names, + stripIndents, + workspaceRoot, +} from '@nx/devkit'; import fetch from 'node-fetch'; import { NormalizedSchema } from '../schema'; @@ -27,28 +34,41 @@ export async function generateBootProject( ); logger.info( - `📦 Extracting Spring Boot project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...` + `📦 Extracting Spring Boot project zip to '${joinPathFragments( + workspaceRoot, + options.projectRoot + )}'...` ); if (response.ok) { - await extractFromZipStream(response.body, (entryPath, entryContent) => { + await extractFromZipStream(response.body, (entryPath, entryContent) => { const execPermission = - entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew') ? '755' : undefined; + entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew') + ? '755' + : undefined; - if (getMavenWrapperFiles().includes(entryPath) || getGradleWrapperFiles().includes(entryPath)) { + if ( + getMavenWrapperFiles().includes(entryPath) || + getGradleWrapperFiles().includes(entryPath) + ) { if (options.transformIntoMultiModule) { tree.write(`${options.moduleRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } - if (options.keepProjectLevelWrapper) { + if ( + (options.transformIntoMultiModule || + options.addToExistingParentModule) && + options.keepProjectLevelWrapper + ) { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } - - } - else if (options.projectType !== 'library' || !getBootApplicationOnlyFiles(options).includes(entryPath)) { + } else if ( + options.projectType !== 'library' || + !getBootApplicationOnlyFiles(options).includes(entryPath) + ) { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); @@ -56,8 +76,9 @@ export async function generateBootProject( }); } else { throw new Error(stripIndents` - ❌ Error downloading Spring Boot project zip from '${options.springInitializerUrl - }' + ❌ Error downloading Spring Boot project zip from '${ + options.springInitializerUrl + }' If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information: ------------------------------------------------------ Download URL: ${downloadUrl} @@ -68,14 +89,21 @@ export async function generateBootProject( } } - function getBootApplicationOnlyFiles(options: NormalizedSchema) { - const basePath = options.packageName?.replaceAll('.', '/'); - const ext = options.language === 'kotlin' ? '.kt' : options.language === 'groovy' ? '.groovy' : '.java'; + const ext = + options.language === 'kotlin' + ? '.kt' + : options.language === 'groovy' + ? '.groovy' + : '.java'; return [ `src/main/resources/application.properties`, - `src/main/${options.language}/${basePath}/${names(options.name).className}Application${ext}`, - `src/test/${options.language}/${basePath}/${names(options.name).className}ApplicationTests${ext}`]; - -} \ No newline at end of file + `src/main/${options.language}/${basePath}/${ + names(options.name).className + }Application${ext}`, + `src/test/${options.language}/${basePath}/${ + names(options.name).className + }ApplicationTests${ext}`, + ]; +}