From 2869654872b6de698ed7d0d5a92335bfc19df081 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 --- .github/workflows/ci.yml | 2 +- .husky/pre-commit | 2 + package.json | 5 +- .../nx-ktor/src/generators/preset/schema.json | 2 +- .../project/lib/generate-ktor-project.ts | 29 ++- .../lib/prompt-multi-module-support.ts | 214 +++++++++++------- .../src/generators/project/schema.json | 2 +- .../src/generators/preset/schema.json | 2 +- .../project/lib/generate-micronaut-project.ts | 27 ++- .../lib/prompt-multi-module-support.ts | 214 +++++++++++------- .../src/generators/project/schema.json | 31 +-- .../src/generators/preset/schema.json | 2 +- .../project/lib/generate-quarkus-project.ts | 27 ++- .../lib/prompt-multi-module-support.ts | 214 +++++++++++------- .../src/generators/project/schema.json | 12 +- .../src/generators/preset/schema.json | 2 +- .../project/lib/generate-boot-project.ts | 56 +++-- .../lib/prompt-multi-module-support.ts | 211 ++++++++++------- .../src/generators/project/schema.json | 2 +- 19 files changed, 652 insertions(+), 404 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dd093fc..17e414ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,4 +46,4 @@ jobs: main-branch-name: 'develop' - run: pnpm exec nx-cloud record -- nx format:check - - run: pnpm exec nx affected -t lint test build e2e --exclude=smoke --codeCoverage + - run: pnpm exec nx affected -t lint test build e2e-ci --parallel=6 --exclude=smoke --codeCoverage diff --git a/.husky/pre-commit b/.husky/pre-commit index 43cee7ba..cd7a63d1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,8 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" +pnpm affected:format pnpm affected:lint pnpm affected:test pnpm sync-preset-schemas +git add -u diff --git a/package.json b/package.json index b7ed9351..27aea8b9 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,9 @@ "affected:e2e": "nx affected --target e2e --exclude=smoke", "affected:test": "nx affected --target test --exclude=smoke", "affected:lint": "nx affected --target lint --fix", + "affected:format": "nx affected --target format", "affected:graph": "nx affected --graph", - "format": "nx format ", - "format:write": "nx format:write", - "format:check": "nx format:check", + "format": "nx format --base head~1", "migrate": "nx migrate latest", "run-migrate": "nx migrate --run-migrations --if-exists", "graph": "nx graph", diff --git a/packages/nx-ktor/src/generators/preset/schema.json b/packages/nx-ktor/src/generators/preset/schema.json index 6063c3e5..2611b00e 100644 --- a/packages/nx-ktor/src/generators/preset/schema.json +++ b/packages/nx-ktor/src/generators/preset/schema.json @@ -163,7 +163,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/dZelN for more information.", "type": "boolean", - "default": false + "default": true }, "ktorInitializrUrl": { "type": "string", 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..a9590a0e 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 @@ -1,4 +1,10 @@ -import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit'; +import { + Tree, + joinPathFragments, + logger, + stripIndents, + workspaceRoot, +} from '@nx/devkit'; import fetch from 'node-fetch'; import { NormalizedSchema } from '../schema'; @@ -6,7 +12,7 @@ import { buildKtorDownloadUrl } from '../../../utils/ktor-utils'; import { NX_KTOR_PKG } from '../../../index'; import { extractFromZipStream, - getCommonHttpHeaders, + getCommonHttpHeaders, getGradleWrapperFiles, getMavenWrapperFiles, } from '@nxrocks/common-jvm'; @@ -35,7 +41,10 @@ export async function generateKtorProject( const response = await fetch(downloadUrl, downloadOptions); logger.info( - `📦 Extracting Ktor project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...` + `📦 Extracting Ktor project zip to '${joinPathFragments( + workspaceRoot, + options.projectRoot + )}'...` ); if (response.ok) { @@ -44,7 +53,10 @@ export async function generateKtorProject( 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, @@ -55,9 +67,7 @@ export async function generateKtorProject( mode: execPermission, }); } - - } - else { + } else { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); @@ -65,8 +75,9 @@ export async function generateKtorProject( }); } else { throw new Error(stripIndents` - ❌ Error downloading Ktor project zip from '${options.ktorInitializrUrl - }' + ❌ Error downloading Ktor project zip from '${ + options.ktorInitializrUrl + }' If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information: ------------------------------------------------------ Download URL: ${downloadUrl} diff --git a/packages/nx-ktor/src/generators/project/lib/prompt-multi-module-support.ts b/packages/nx-ktor/src/generators/project/lib/prompt-multi-module-support.ts index a3ac8f60..9524005b 100644 --- a/packages/nx-ktor/src/generators/project/lib/prompt-multi-module-support.ts +++ b/packages/nx-ktor/src/generators/project/lib/prompt-multi-module-support.ts @@ -1,97 +1,151 @@ -import { logger, createProjectGraphAsync, ProjectGraph, Tree } from "@nx/devkit"; +import { + logger, + createProjectGraphAsync, + ProjectGraph, + Tree, +} from '@nx/devkit'; import { prompt } from 'enquirer'; -import { NormalizedSchema } from "../schema"; -import { addGradleModule, addMavenModule, initGradleParentModule, initMavenParentModule, hasMultiModuleGradleProjectInTree, hasMultiModuleMavenProjectInTree, getAdjustedProjectAndModuleRoot } from "@nxrocks/common-jvm"; +import { NormalizedSchema } from '../schema'; +import { + addGradleModule, + addMavenModule, + initGradleParentModule, + initMavenParentModule, + hasMultiModuleGradleProjectInTree, + hasMultiModuleMavenProjectInTree, + getAdjustedProjectAndModuleRoot, +} from '@nxrocks/common-jvm'; -export async function promptForMultiModuleSupport(tree: Tree, options: NormalizedSchema) { +export async function promptForMultiModuleSupport( + tree: Tree, + options: NormalizedSchema +) { + const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; - const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; + if ( + (options.transformIntoMultiModule === undefined || + options.addToExistingParentModule === undefined) && + options.parentModuleName === undefined && + process.env.NX_INTERACTIVE === 'true' + ) { + logger.info( + `⏳ Checking for existing multi-module projects. Please wait...` + ); - if ( - (options.transformIntoMultiModule === undefined || options.addToExistingParentModule === undefined) && - options.parentModuleName === undefined && - process.env.NX_INTERACTIVE === 'true' - ) { - logger.info(`⏳ Checking for existing multi-module projects. Please wait...`); + const projectGraph: ProjectGraph = await createProjectGraphAsync(); - const projectGraph: ProjectGraph = await createProjectGraphAsync(); + const multiModuleProjects = Object.values(projectGraph.nodes) + .map((n) => n.data) + .filter((project) => + options.buildSystem === 'MAVEN' + ? hasMultiModuleMavenProjectInTree(tree, project.root) + : hasMultiModuleGradleProjectInTree(tree, project.root) + ); - const multiModuleProjects = Object.values(projectGraph.nodes).map(n => n.data).filter(project => options.buildSystem === 'MAVEN' ? hasMultiModuleMavenProjectInTree(tree, project.root) : hasMultiModuleGradleProjectInTree(tree, project.root)) + if (multiModuleProjects.length === 0) { + options.transformIntoMultiModule = await prompt({ + name: 'transformIntoMultiModule', + message: `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, + type: 'confirm', + initial: false, + }).then((a) => a['transformIntoMultiModule']); - if (multiModuleProjects.length === 0) { - options.transformIntoMultiModule = await prompt({ - name: 'transformIntoMultiModule', - message: - `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, - type: 'confirm', - initial: false - }).then((a) => a['transformIntoMultiModule']); + if (options.transformIntoMultiModule) { + options.parentModuleName = ( + await prompt({ + name: 'parentModuleName', + message: `What name would you like to use for the ${buildSystemName} multi-module project?`, + type: 'input', + initial: `${options.projectName}-parent`, + }).then((a) => a['parentModuleName']) + ).replace(/\//g, '-'); - if (options.transformIntoMultiModule) { - options.parentModuleName = (await prompt({ - name: 'parentModuleName', - message: - `What name would you like to use for the ${buildSystemName} multi-module project?`, - type: 'input', - initial: `${options.projectName}-parent` - }).then((a) => a['parentModuleName'])).replace(/\//g, '-'); - - options.keepProjectLevelWrapper ??= false; - } - } - else { - options.addToExistingParentModule = await prompt({ - name: 'addToExistingParentModule', - message: - `We found ${multiModuleProjects.length} existing ${buildSystemName} multi-module projects in your workaspace${multiModuleProjects.length === 1 ? `('${multiModuleProjects[0].name}')` : ''}.\nWould you like to add this new project ${multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?'}`, - type: 'confirm', - initial: false - }).then((a) => a['addToExistingParentModule']); - - if (options.addToExistingParentModule) { - if (multiModuleProjects.length === 1) { - options.parentModuleName = multiModuleProjects[0].name; - } - else { - options.parentModuleName = await prompt({ - name: 'parentModuleName', - message: - 'Which parent module would you like to add the new project into?', - type: 'select', - choices: multiModuleProjects.map(p => p.name), - }).then((a) => a['parentModuleName']); - } - } + options.keepProjectLevelWrapper ??= true; + } + } else { + options.addToExistingParentModule = await prompt({ + name: 'addToExistingParentModule', + message: `We found ${ + multiModuleProjects.length + } existing ${buildSystemName} multi-module projects in your workaspace${ + multiModuleProjects.length === 1 + ? `('${multiModuleProjects[0].name}')` + : '' + }.\nWould you like to add this new project ${ + multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?' + }`, + type: 'confirm', + initial: false, + }).then((a) => a['addToExistingParentModule']); + if (options.addToExistingParentModule) { + if (multiModuleProjects.length === 1) { + options.parentModuleName = multiModuleProjects[0].name; + } else { + options.parentModuleName = await prompt({ + name: 'parentModuleName', + message: + 'Which parent module would you like to add the new project into?', + type: 'select', + choices: multiModuleProjects.map((p) => p.name), + }).then((a) => a['parentModuleName']); } + } } - if ((options.transformIntoMultiModule || options.addToExistingParentModule) && options.parentModuleName) { - const isMavenProject = options.buildSystem === 'MAVEN'; - const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${isMavenProject ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html'}`; + } + if ( + (options.transformIntoMultiModule || options.addToExistingParentModule) && + options.parentModuleName + ) { + const isMavenProject = options.buildSystem === 'MAVEN'; + const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${ + isMavenProject + ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' + : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html' + }`; - const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); + const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); - options.projectRoot = opts.projectRoot; - options.moduleRoot = opts.moduleRoot; + options.projectRoot = opts.projectRoot; + options.moduleRoot = opts.moduleRoot; - if (options.transformIntoMultiModule) { - // add the root module - if (isMavenProject) { - initMavenParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, ``); - } - else { - initGradleParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, opts.offsetFromRoot, options.buildSystem === 'GRADLE_KTS', `// ${helpComment}`); - } - } - else if (options.addToExistingParentModule) { - // add to the chosen root module - if (isMavenProject) { - addMavenModule(tree, options.moduleRoot, options.projectName); - } - else { - addGradleModule(tree, options.moduleRoot, options.projectName, opts.offsetFromRoot, options.buildSystem === 'GRADLE_KTS'); - } - } + if (options.transformIntoMultiModule) { + // add the root module + if (isMavenProject) { + initMavenParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + `` + ); + } else { + initGradleParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KTS', + `// ${helpComment}` + ); + } + } else if (options.addToExistingParentModule) { + // add to the chosen root module + if (isMavenProject) { + addMavenModule(tree, options.moduleRoot, options.projectName); + } else { + addGradleModule( + tree, + options.moduleRoot, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KTS' + ); + } } + } } diff --git a/packages/nx-ktor/src/generators/project/schema.json b/packages/nx-ktor/src/generators/project/schema.json index 54034318..c503772d 100644 --- a/packages/nx-ktor/src/generators/project/schema.json +++ b/packages/nx-ktor/src/generators/project/schema.json @@ -158,7 +158,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/dZelN for more information.", "type": "boolean", - "default": false + "default": true }, "ktorInitializrUrl": { "type": "string", diff --git a/packages/nx-micronaut/src/generators/preset/schema.json b/packages/nx-micronaut/src/generators/preset/schema.json index c8bcee7c..17c44569 100644 --- a/packages/nx-micronaut/src/generators/preset/schema.json +++ b/packages/nx-micronaut/src/generators/preset/schema.json @@ -227,7 +227,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/ov0Y9 for more information.", "type": "boolean", - "default": false + "default": true }, "micronautLaunchUrl": { "type": "string", 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..9244fefe 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 @@ -1,4 +1,10 @@ -import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit'; +import { + Tree, + joinPathFragments, + logger, + stripIndents, + workspaceRoot, +} from '@nx/devkit'; import fetch from 'node-fetch'; import { NormalizedSchema } from '../schema'; @@ -27,7 +33,10 @@ export async function generateMicronautProject( ); logger.info( - `📦 Extracting Micronaut project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...` + `📦 Extracting Micronaut project zip to '${joinPathFragments( + workspaceRoot, + options.projectRoot + )}'...` ); if (response.ok) { @@ -40,7 +49,10 @@ export async function generateMicronautProject( filePath.endsWith('mvnw') || filePath.endsWith('gradlew') ? '755' : undefined; - if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) { + if ( + getMavenWrapperFiles().includes(filePath) || + getGradleWrapperFiles().includes(filePath) + ) { if (options.transformIntoMultiModule) { tree.write(`${options.moduleRoot}/${filePath}`, entryContent, { mode: execPermission, @@ -51,9 +63,7 @@ export async function generateMicronautProject( mode: execPermission, }); } - - } - else { + } else { tree.write(`${options.projectRoot}/${filePath}`, entryContent, { mode: execPermission, }); @@ -61,8 +71,9 @@ export async function generateMicronautProject( }); } else { throw new Error(stripIndents` - ❌ Error downloading Micronaut project zip from '${options.micronautLaunchUrl - }' + ❌ Error downloading Micronaut project zip from '${ + options.micronautLaunchUrl + }' If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information: ------------------------------------------------------ Download URL: ${downloadUrl} diff --git a/packages/nx-micronaut/src/generators/project/lib/prompt-multi-module-support.ts b/packages/nx-micronaut/src/generators/project/lib/prompt-multi-module-support.ts index 43ca0b4a..fc34a527 100644 --- a/packages/nx-micronaut/src/generators/project/lib/prompt-multi-module-support.ts +++ b/packages/nx-micronaut/src/generators/project/lib/prompt-multi-module-support.ts @@ -1,97 +1,151 @@ -import { logger, createProjectGraphAsync, ProjectGraph, Tree } from "@nx/devkit"; +import { + logger, + createProjectGraphAsync, + ProjectGraph, + Tree, +} from '@nx/devkit'; import { prompt } from 'enquirer'; -import { NormalizedSchema } from "../schema"; -import { addGradleModule, addMavenModule, initGradleParentModule, initMavenParentModule, hasMultiModuleGradleProjectInTree, hasMultiModuleMavenProjectInTree, getAdjustedProjectAndModuleRoot } from "@nxrocks/common-jvm"; +import { NormalizedSchema } from '../schema'; +import { + addGradleModule, + addMavenModule, + initGradleParentModule, + initMavenParentModule, + hasMultiModuleGradleProjectInTree, + hasMultiModuleMavenProjectInTree, + getAdjustedProjectAndModuleRoot, +} from '@nxrocks/common-jvm'; -export async function promptForMultiModuleSupport(tree: Tree, options: NormalizedSchema) { +export async function promptForMultiModuleSupport( + tree: Tree, + options: NormalizedSchema +) { + const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; + if ( + (options.transformIntoMultiModule === undefined || + options.addToExistingParentModule === undefined) && + options.parentModuleName === undefined && + process.env.NX_INTERACTIVE === 'true' + ) { + logger.info( + `⏳ Checking for existing multi-module projects. Please wait...` + ); - const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; - if ( - (options.transformIntoMultiModule === undefined || options.addToExistingParentModule === undefined) && - options.parentModuleName === undefined && - process.env.NX_INTERACTIVE === 'true' - ) { - logger.info(`⏳ Checking for existing multi-module projects. Please wait...`); + const projectGraph: ProjectGraph = await createProjectGraphAsync(); - const projectGraph: ProjectGraph = await createProjectGraphAsync(); + const multiModuleProjects = Object.values(projectGraph.nodes) + .map((n) => n.data) + .filter((project) => + options.buildSystem === 'MAVEN' + ? hasMultiModuleMavenProjectInTree(tree, project.root) + : hasMultiModuleGradleProjectInTree(tree, project.root) + ); - const multiModuleProjects = Object.values(projectGraph.nodes).map(n => n.data).filter(project => options.buildSystem === 'MAVEN' ? hasMultiModuleMavenProjectInTree(tree, project.root) : hasMultiModuleGradleProjectInTree(tree, project.root)) + if (multiModuleProjects.length === 0) { + options.transformIntoMultiModule = await prompt({ + name: 'transformIntoMultiModule', + message: `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, + type: 'confirm', + initial: false, + }).then((a) => a['transformIntoMultiModule']); - if (multiModuleProjects.length === 0) { - options.transformIntoMultiModule = await prompt({ - name: 'transformIntoMultiModule', - message: - `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, - type: 'confirm', - initial: false - }).then((a) => a['transformIntoMultiModule']); + if (options.transformIntoMultiModule) { + options.parentModuleName = ( + await prompt({ + name: 'parentModuleName', + message: `What name would you like to use for the ${buildSystemName} multi-module project?`, + type: 'input', + initial: `${options.projectName}-parent`, + }).then((a) => a['parentModuleName']) + ).replace(/\//g, '-'); - if (options.transformIntoMultiModule) { - options.parentModuleName = (await prompt({ - name: 'parentModuleName', - message: - `What name would you like to use for the ${buildSystemName} multi-module project?`, - type: 'input', - initial: `${options.projectName}-parent` - }).then((a) => a['parentModuleName'])).replace(/\//g, '-'); - - options.keepProjectLevelWrapper ??= false; - } - } - else { - options.addToExistingParentModule = await prompt({ - name: 'addToExistingParentModule', - message: - `We found ${multiModuleProjects.length} existing ${buildSystemName} multi-module projects in your workaspace${multiModuleProjects.length === 1 ? `('${multiModuleProjects[0].name}')` : ''}.\nWould you like to add this new project ${multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?'}`, - type: 'confirm', - initial: false - }).then((a) => a['addToExistingParentModule']); - - if (options.addToExistingParentModule) { - if (multiModuleProjects.length === 1) { - options.parentModuleName = multiModuleProjects[0].name; - } - else { - options.parentModuleName = await prompt({ - name: 'parentModuleName', - message: - 'Which parent module would you like to add the new project into?', - type: 'select', - choices: multiModuleProjects.map(p => p.name), - }).then((a) => a['parentModuleName']); - } - } + options.keepProjectLevelWrapper ??= true; + } + } else { + options.addToExistingParentModule = await prompt({ + name: 'addToExistingParentModule', + message: `We found ${ + multiModuleProjects.length + } existing ${buildSystemName} multi-module projects in your workaspace${ + multiModuleProjects.length === 1 + ? `('${multiModuleProjects[0].name}')` + : '' + }.\nWould you like to add this new project ${ + multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?' + }`, + type: 'confirm', + initial: false, + }).then((a) => a['addToExistingParentModule']); + if (options.addToExistingParentModule) { + if (multiModuleProjects.length === 1) { + options.parentModuleName = multiModuleProjects[0].name; + } else { + options.parentModuleName = await prompt({ + name: 'parentModuleName', + message: + 'Which parent module would you like to add the new project into?', + type: 'select', + choices: multiModuleProjects.map((p) => p.name), + }).then((a) => a['parentModuleName']); } + } } + } - if((options.transformIntoMultiModule || options.addToExistingParentModule) && options.parentModuleName){ - const isMavenProject = options.buildSystem === 'MAVEN'; - const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${isMavenProject ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html'}`; + if ( + (options.transformIntoMultiModule || options.addToExistingParentModule) && + options.parentModuleName + ) { + const isMavenProject = options.buildSystem === 'MAVEN'; + const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${ + isMavenProject + ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' + : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html' + }`; - const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); + const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); - options.projectRoot = opts.projectRoot; - options.moduleRoot = opts.moduleRoot; + options.projectRoot = opts.projectRoot; + options.moduleRoot = opts.moduleRoot; - if(options.transformIntoMultiModule){ - // add the root module - if(isMavenProject){ - initMavenParentModule(tree, options.moduleRoot, options.basePackage, options.parentModuleName, options.projectName, ``); - } - else { - initGradleParentModule(tree, options.moduleRoot, options.basePackage, options.parentModuleName, options.projectName, opts.offsetFromRoot, options. buildSystem === 'GRADLE_KOTLIN', `// ${helpComment}`); - } - } - else if(options.addToExistingParentModule){ - // add to the chosen root module - if(isMavenProject){ - addMavenModule(tree, options.moduleRoot, options.projectName); - } - else { - addGradleModule(tree, options.moduleRoot, options.projectName, opts.offsetFromRoot, options. buildSystem === 'GRADLE_KOTLIN'); - } - } + if (options.transformIntoMultiModule) { + // add the root module + if (isMavenProject) { + initMavenParentModule( + tree, + options.moduleRoot, + options.basePackage, + options.parentModuleName, + options.projectName, + `` + ); + } else { + initGradleParentModule( + tree, + options.moduleRoot, + options.basePackage, + options.parentModuleName, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KOTLIN', + `// ${helpComment}` + ); + } + } else if (options.addToExistingParentModule) { + // add to the chosen root module + if (isMavenProject) { + addMavenModule(tree, options.moduleRoot, options.projectName); + } else { + addGradleModule( + tree, + options.moduleRoot, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KOTLIN' + ); + } } + } } diff --git a/packages/nx-micronaut/src/generators/project/schema.json b/packages/nx-micronaut/src/generators/project/schema.json index 59cbdc4a..8ae66779 100644 --- a/packages/nx-micronaut/src/generators/project/schema.json +++ b/packages/nx-micronaut/src/generators/project/schema.json @@ -60,11 +60,7 @@ "description": "Micronaut version.", "type": "string", "default": "current", - "enum": [ - "current", - "snapshot", - "previous" - ], + "enum": ["current", "snapshot", "previous"], "x-prompt": { "message": "Which version of Micronaut would you like to use?", "type": "list", @@ -114,11 +110,7 @@ "description": "Java version.", "type": "string", "default": "JDK_17", - "enum": [ - "JDK_8", - "JDK_11", - "JDK_17" - ], + "enum": ["JDK_8", "JDK_11", "JDK_17"], "x-prompt": { "message": "Which version of Java would you like to use?", "type": "list", @@ -143,11 +135,7 @@ "description": "Language of the project.", "type": "string", "default": "JAVA", - "enum": [ - "JAVA", - "KOTLIN", - "GROOVY" - ], + "enum": ["JAVA", "KOTLIN", "GROOVY"], "x-prompt": { "message": "Which language would you like to use?", "type": "list", @@ -179,11 +167,7 @@ "description": "Test framework to use.", "type": "string", "default": "JUNIT", - "enum": [ - "JUNIT", - "SPOCK", - "KOTEST" - ], + "enum": ["JUNIT", "SPOCK", "KOTEST"], "x-prompt": { "message": "Which test framework would you like to use?", "type": "list", @@ -231,7 +215,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/ov0Y9 for more information.", "type": "boolean", - "default": false + "default": true }, "micronautLaunchUrl": { "type": "string", @@ -256,8 +240,5 @@ "enum": ["as-provided", "derived"] } }, - "required": [ - "projectType", - "name" - ] + "required": ["projectType", "name"] } diff --git a/packages/nx-quarkus/src/generators/preset/schema.json b/packages/nx-quarkus/src/generators/preset/schema.json index d001c4d6..4e50f301 100644 --- a/packages/nx-quarkus/src/generators/preset/schema.json +++ b/packages/nx-quarkus/src/generators/preset/schema.json @@ -127,7 +127,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/TmKF- for more information.", "type": "boolean", - "default": false + "default": true }, "quarkusInitializerUrl": { "type": "string", 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..aa282309 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 @@ -1,4 +1,10 @@ -import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit'; +import { + Tree, + joinPathFragments, + logger, + stripIndents, + workspaceRoot, +} from '@nx/devkit'; import fetch from 'node-fetch'; import { NormalizedSchema } from '../schema'; @@ -25,7 +31,10 @@ export async function generateQuarkusProject( ); logger.info( - `📦 Extracting Quarkus project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...` + `📦 Extracting Quarkus project zip to '${joinPathFragments( + workspaceRoot, + options.projectRoot + )}'...` ); if (response.ok) { @@ -35,7 +44,10 @@ export async function generateQuarkusProject( filePath.endsWith('mvnw') || filePath.endsWith('gradlew') ? '755' : undefined; - if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) { + if ( + getMavenWrapperFiles().includes(filePath) || + getGradleWrapperFiles().includes(filePath) + ) { if (options.transformIntoMultiModule) { tree.write(`${options.moduleRoot}/${filePath}`, entryContent, { mode: execPermission, @@ -46,9 +58,7 @@ export async function generateQuarkusProject( mode: execPermission, }); } - - } - else { + } else { tree.write(`${options.projectRoot}/${filePath}`, entryContent, { mode: execPermission, }); @@ -56,8 +66,9 @@ export async function generateQuarkusProject( }); } else { throw new Error(stripIndents` - ❌ Error downloading Quarkus project zip from '${options.quarkusInitializerUrl - }' + ❌ Error downloading Quarkus project zip from '${ + options.quarkusInitializerUrl + }' If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information: ------------------------------------------------------ Download URL: ${downloadUrl} diff --git a/packages/nx-quarkus/src/generators/project/lib/prompt-multi-module-support.ts b/packages/nx-quarkus/src/generators/project/lib/prompt-multi-module-support.ts index b08e716e..b3d9b0d2 100644 --- a/packages/nx-quarkus/src/generators/project/lib/prompt-multi-module-support.ts +++ b/packages/nx-quarkus/src/generators/project/lib/prompt-multi-module-support.ts @@ -1,97 +1,151 @@ -import { logger, createProjectGraphAsync, ProjectGraph, Tree } from "@nx/devkit"; +import { + logger, + createProjectGraphAsync, + ProjectGraph, + Tree, +} from '@nx/devkit'; import { prompt } from 'enquirer'; -import { NormalizedSchema } from "../schema"; -import { addGradleModule, addMavenModule, initGradleParentModule, initMavenParentModule, hasMultiModuleGradleProjectInTree, hasMultiModuleMavenProjectInTree, getAdjustedProjectAndModuleRoot } from "@nxrocks/common-jvm"; +import { NormalizedSchema } from '../schema'; +import { + addGradleModule, + addMavenModule, + initGradleParentModule, + initMavenParentModule, + hasMultiModuleGradleProjectInTree, + hasMultiModuleMavenProjectInTree, + getAdjustedProjectAndModuleRoot, +} from '@nxrocks/common-jvm'; -export async function promptForMultiModuleSupport(tree: Tree, options: NormalizedSchema) { +export async function promptForMultiModuleSupport( + tree: Tree, + options: NormalizedSchema +) { + const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; + if ( + (options.transformIntoMultiModule === undefined || + options.addToExistingParentModule === undefined) && + options.parentModuleName === undefined && + process.env.NX_INTERACTIVE === 'true' + ) { + logger.info( + `⏳ Checking for existing multi-module projects. Please wait...` + ); - const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; - if ( - (options.transformIntoMultiModule === undefined || options.addToExistingParentModule === undefined) && - options.parentModuleName === undefined && - process.env.NX_INTERACTIVE === 'true' - ) { - logger.info(`⏳ Checking for existing multi-module projects. Please wait...`); + const projectGraph: ProjectGraph = await createProjectGraphAsync(); - const projectGraph: ProjectGraph = await createProjectGraphAsync(); + const multiModuleProjects = Object.values(projectGraph.nodes) + .map((n) => n.data) + .filter((project) => + options.buildSystem === 'MAVEN' + ? hasMultiModuleMavenProjectInTree(tree, project.root) + : hasMultiModuleGradleProjectInTree(tree, project.root) + ); - const multiModuleProjects = Object.values(projectGraph.nodes).map(n => n.data).filter(project => options.buildSystem === 'MAVEN' ? hasMultiModuleMavenProjectInTree(tree, project.root) : hasMultiModuleGradleProjectInTree(tree, project.root)) + if (multiModuleProjects.length === 0) { + options.transformIntoMultiModule = await prompt({ + name: 'transformIntoMultiModule', + message: `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, + type: 'confirm', + initial: false, + }).then((a) => a['transformIntoMultiModule']); - if (multiModuleProjects.length === 0) { - options.transformIntoMultiModule = await prompt({ - name: 'transformIntoMultiModule', - message: - `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, - type: 'confirm', - initial: false - }).then((a) => a['transformIntoMultiModule']); + if (options.transformIntoMultiModule) { + options.parentModuleName = ( + await prompt({ + name: 'parentModuleName', + message: `What name would you like to use for the ${buildSystemName} multi-module project?`, + type: 'input', + initial: `${options.projectName}-parent`, + }).then((a) => a['parentModuleName']) + ).replace(/\//g, '-'); - if (options.transformIntoMultiModule) { - options.parentModuleName = (await prompt({ - name: 'parentModuleName', - message: - `What name would you like to use for the ${buildSystemName} multi-module project?`, - type: 'input', - initial: `${options.projectName}-parent` - }).then((a) => a['parentModuleName'])).replace(/\//g, '-'); - - options.keepProjectLevelWrapper ??= false; - } - } - else { - options.addToExistingParentModule = await prompt({ - name: 'addToExistingParentModule', - message: - `We found ${multiModuleProjects.length} existing ${buildSystemName} multi-module projects in your workaspace${multiModuleProjects.length === 1 ? `('${multiModuleProjects[0].name}')` : ''}.\nWould you like to add this new project ${multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?'}`, - type: 'confirm', - initial: false - }).then((a) => a['addToExistingParentModule']); - - if (options.addToExistingParentModule) { - if (multiModuleProjects.length === 1) { - options.parentModuleName = multiModuleProjects[0].name; - } - else { - options.parentModuleName = await prompt({ - name: 'parentModuleName', - message: - 'Which parent module would you like to add the new project into?', - type: 'select', - choices: multiModuleProjects.map(p => p.name), - }).then((a) => a['parentModuleName']); - } - } + options.keepProjectLevelWrapper ??= true; + } + } else { + options.addToExistingParentModule = await prompt({ + name: 'addToExistingParentModule', + message: `We found ${ + multiModuleProjects.length + } existing ${buildSystemName} multi-module projects in your workaspace${ + multiModuleProjects.length === 1 + ? `('${multiModuleProjects[0].name}')` + : '' + }.\nWould you like to add this new project ${ + multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?' + }`, + type: 'confirm', + initial: false, + }).then((a) => a['addToExistingParentModule']); + if (options.addToExistingParentModule) { + if (multiModuleProjects.length === 1) { + options.parentModuleName = multiModuleProjects[0].name; + } else { + options.parentModuleName = await prompt({ + name: 'parentModuleName', + message: + 'Which parent module would you like to add the new project into?', + type: 'select', + choices: multiModuleProjects.map((p) => p.name), + }).then((a) => a['parentModuleName']); } + } } + } - if ((options.transformIntoMultiModule || options.addToExistingParentModule) && options.parentModuleName) { - const isMavenProject = options.buildSystem === 'MAVEN'; - const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${isMavenProject ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html'}`; + if ( + (options.transformIntoMultiModule || options.addToExistingParentModule) && + options.parentModuleName + ) { + const isMavenProject = options.buildSystem === 'MAVEN'; + const helpComment = `For more information about ${buildSystemName} multi-modules projects, go to: ${ + isMavenProject + ? 'https://maven.apache.org/guides/mini/guide-multiple-modules-4.html' + : 'https://docs.gradle.org/current/userguide/intro_multi_project_builds.html' + }`; - const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); + const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); - options.projectRoot = opts.projectRoot; - options.moduleRoot = opts.moduleRoot; + options.projectRoot = opts.projectRoot; + options.moduleRoot = opts.moduleRoot; - if (options.transformIntoMultiModule) { - // add the root module - if (isMavenProject) { - initMavenParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, ``); - } - else { - initGradleParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, opts.offsetFromRoot, options.buildSystem === 'GRADLE_KOTLIN_DSL', `// ${helpComment}`); - } - } - else if (options.addToExistingParentModule) { - // add to the chosen root module - if (isMavenProject) { - addMavenModule(tree, options.moduleRoot, options.projectName); - } - else { - addGradleModule(tree, options.moduleRoot, options.projectName, opts.offsetFromRoot, options.buildSystem === 'GRADLE_KOTLIN_DSL'); - } - } + if (options.transformIntoMultiModule) { + // add the root module + if (isMavenProject) { + initMavenParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + `` + ); + } else { + initGradleParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KOTLIN_DSL', + `// ${helpComment}` + ); + } + } else if (options.addToExistingParentModule) { + // add to the chosen root module + if (isMavenProject) { + addMavenModule(tree, options.moduleRoot, options.projectName); + } else { + addGradleModule( + tree, + options.moduleRoot, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'GRADLE_KOTLIN_DSL' + ); + } } + } } diff --git a/packages/nx-quarkus/src/generators/project/schema.json b/packages/nx-quarkus/src/generators/project/schema.json index ce4efdf5..b5b086ca 100644 --- a/packages/nx-quarkus/src/generators/project/schema.json +++ b/packages/nx-quarkus/src/generators/project/schema.json @@ -72,10 +72,7 @@ "description": "Java version.", "type": "string", "default": "17", - "enum": [ - "17", - "21" - ], + "enum": ["17", "21"], "x-prompt": { "message": "Which version of Java would you like to use?", "type": "list", @@ -131,7 +128,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/TmKF- for more information.", "type": "boolean", - "default": false + "default": true }, "quarkusInitializerUrl": { "type": "string", @@ -169,8 +166,5 @@ "enum": ["as-provided", "derived"] } }, - "required": [ - "projectType", - "name" - ] + "required": ["projectType", "name"] } diff --git a/packages/nx-spring-boot/src/generators/preset/schema.json b/packages/nx-spring-boot/src/generators/preset/schema.json index ed9f4b38..c004d7e8 100644 --- a/packages/nx-spring-boot/src/generators/preset/schema.json +++ b/packages/nx-spring-boot/src/generators/preset/schema.json @@ -217,7 +217,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/yvsp1 for more information.", "type": "boolean", - "default": false + "default": true }, "springInitializerUrl": { "type": "string", 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..b7fc3bca 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,15 +34,23 @@ 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) => { 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, @@ -46,9 +61,10 @@ export async function generateBootProject( 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 +72,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 +85,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}`, + ]; +} diff --git a/packages/nx-spring-boot/src/generators/project/lib/prompt-multi-module-support.ts b/packages/nx-spring-boot/src/generators/project/lib/prompt-multi-module-support.ts index a2f8a3ec..b9960db0 100644 --- a/packages/nx-spring-boot/src/generators/project/lib/prompt-multi-module-support.ts +++ b/packages/nx-spring-boot/src/generators/project/lib/prompt-multi-module-support.ts @@ -1,96 +1,149 @@ -import { logger, createProjectGraphAsync, ProjectGraph, Tree } from "@nx/devkit"; +import { + logger, + createProjectGraphAsync, + ProjectGraph, + Tree, +} from '@nx/devkit'; import { prompt } from 'enquirer'; -import { NormalizedSchema } from "../schema"; -import { addGradleModule, addMavenModule, initGradleParentModule, initMavenParentModule, hasMultiModuleGradleProjectInTree, hasMultiModuleMavenProjectInTree, getAdjustedProjectAndModuleRoot } from "@nxrocks/common-jvm"; +import { NormalizedSchema } from '../schema'; +import { + addGradleModule, + addMavenModule, + initGradleParentModule, + initMavenParentModule, + hasMultiModuleGradleProjectInTree, + hasMultiModuleMavenProjectInTree, + getAdjustedProjectAndModuleRoot, +} from '@nxrocks/common-jvm'; -export async function promptForMultiModuleSupport(tree: Tree, options: NormalizedSchema) { - if ( - (options.transformIntoMultiModule === undefined || options.addToExistingParentModule === undefined) && - options.parentModuleName === undefined && - process.env.NX_INTERACTIVE === 'true' - ) { - logger.info(`⏳ Checking for existing multi-module projects. Please wait...`); +export async function promptForMultiModuleSupport( + tree: Tree, + options: NormalizedSchema +) { + if ( + (options.transformIntoMultiModule === undefined || + options.addToExistingParentModule === undefined) && + options.parentModuleName === undefined && + process.env.NX_INTERACTIVE === 'true' + ) { + logger.info( + `⏳ Checking for existing multi-module projects. Please wait...` + ); - const projectGraph: ProjectGraph = await createProjectGraphAsync(); + const projectGraph: ProjectGraph = await createProjectGraphAsync(); - const multiModuleProjects = Object.values(projectGraph.nodes).map(n => n.data).filter(project => options.buildSystem === 'maven-project' ? hasMultiModuleMavenProjectInTree(tree, project.root) : hasMultiModuleGradleProjectInTree(tree, project.root)) - const buildSystemName = options.buildSystem === 'maven-project' ? 'Maven' : 'Gradle'; + const multiModuleProjects = Object.values(projectGraph.nodes) + .map((n) => n.data) + .filter((project) => + options.buildSystem === 'maven-project' + ? hasMultiModuleMavenProjectInTree(tree, project.root) + : hasMultiModuleGradleProjectInTree(tree, project.root) + ); + const buildSystemName = + options.buildSystem === 'maven-project' ? 'Maven' : 'Gradle'; - if (multiModuleProjects.length === 0) { - options.transformIntoMultiModule = await prompt({ - name: 'transformIntoMultiModule', - message: - `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, - type: 'confirm', - initial: false - }).then((a) => a['transformIntoMultiModule']); + if (multiModuleProjects.length === 0) { + options.transformIntoMultiModule = await prompt({ + name: 'transformIntoMultiModule', + message: `Would you like to transform the generated project into a ${buildSystemName} multi-module project?`, + type: 'confirm', + initial: false, + }).then((a) => a['transformIntoMultiModule']); - if (options.transformIntoMultiModule) { - options.parentModuleName = (await prompt({ - name: 'multiModuleName', - message: - `What name would you like to use for the ${buildSystemName} multi-module project?`, - type: 'input', - initial: `${options.projectName}-parent` - }).then((a) => a['multiModuleName'])).replace(/\//g, '-'); + if (options.transformIntoMultiModule) { + options.parentModuleName = ( + await prompt({ + name: 'multiModuleName', + message: `What name would you like to use for the ${buildSystemName} multi-module project?`, + type: 'input', + initial: `${options.projectName}-parent`, + }).then((a) => a['multiModuleName']) + ).replace(/\//g, '-'); - options.keepProjectLevelWrapper ??= false; - } - } - else { - options.addToExistingParentModule = await prompt({ - name: 'addToExistingParentModule', - message: - `We found ${multiModuleProjects.length} existing ${buildSystemName} multi-module projects in your workaspace${multiModuleProjects.length === 1 ? `('${multiModuleProjects[0].name}')` : ''}.\nWould you like to add this new project ${multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?'}`, - type: 'confirm', - initial: false - }).then((a) => a['addToExistingParentModule']); - - if (options.addToExistingParentModule) { - if (multiModuleProjects.length === 1) { - options.parentModuleName = multiModuleProjects[0].name; - } - else { - options.parentModuleName = await prompt({ - name: 'parentModuleName', - message: - 'Which parent module would you like to add the new project into?', - type: 'select', - choices: multiModuleProjects.map(p => p.name), - }).then((a) => a['parentModuleName']); - } - } + options.keepProjectLevelWrapper ??= true; + } + } else { + options.addToExistingParentModule = await prompt({ + name: 'addToExistingParentModule', + message: `We found ${ + multiModuleProjects.length + } existing ${buildSystemName} multi-module projects in your workaspace${ + multiModuleProjects.length === 1 + ? `('${multiModuleProjects[0].name}')` + : '' + }.\nWould you like to add this new project ${ + multiModuleProjects.length === 1 ? 'to it?' : 'into one of them?' + }`, + type: 'confirm', + initial: false, + }).then((a) => a['addToExistingParentModule']); + if (options.addToExistingParentModule) { + if (multiModuleProjects.length === 1) { + options.parentModuleName = multiModuleProjects[0].name; + } else { + options.parentModuleName = await prompt({ + name: 'parentModuleName', + message: + 'Which parent module would you like to add the new project into?', + type: 'select', + choices: multiModuleProjects.map((p) => p.name), + }).then((a) => a['parentModuleName']); } + } } + } - if ((options.transformIntoMultiModule || options.addToExistingParentModule) && options.parentModuleName) { - const helpComment = 'For more information about Spring boot multi-modules projects, go to: https://spring.io/guides/gs/multi-module/'; + if ( + (options.transformIntoMultiModule || options.addToExistingParentModule) && + options.parentModuleName + ) { + const helpComment = + 'For more information about Spring boot multi-modules projects, go to: https://spring.io/guides/gs/multi-module/'; - const isMavenProject = options.buildSystem === 'maven-project'; - const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); + const isMavenProject = options.buildSystem === 'maven-project'; + const opts = await getAdjustedProjectAndModuleRoot(options, isMavenProject); - options.projectRoot = opts.projectRoot; - options.moduleRoot = opts.moduleRoot; + options.projectRoot = opts.projectRoot; + options.moduleRoot = opts.moduleRoot; - if (options.transformIntoMultiModule) { - // add the root module - if (isMavenProject) { - initMavenParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, ``); - } - else { - initGradleParentModule(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, opts.offsetFromRoot, options.buildSystem === 'gradle-project-kotlin', `// ${helpComment}`); - } - } - else if (options.addToExistingParentModule) { - // add to the chosen root module - if (isMavenProject) { - addMavenModule(tree, options.moduleRoot, options.projectName); - } - else { - addGradleModule(tree, options.moduleRoot, options.projectName, opts.offsetFromRoot, options.buildSystem === 'gradle-project-kotlin'); - } - } + if (options.transformIntoMultiModule) { + // add the root module + if (isMavenProject) { + initMavenParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + `` + ); + } else { + initGradleParentModule( + tree, + options.moduleRoot, + options.groupId, + options.parentModuleName, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'gradle-project-kotlin', + `// ${helpComment}` + ); + } + } else if (options.addToExistingParentModule) { + // add to the chosen root module + if (isMavenProject) { + addMavenModule(tree, options.moduleRoot, options.projectName); + } else { + addGradleModule( + tree, + options.moduleRoot, + options.projectName, + opts.offsetFromRoot, + options.buildSystem === 'gradle-project-kotlin' + ); + } } + } } diff --git a/packages/nx-spring-boot/src/generators/project/schema.json b/packages/nx-spring-boot/src/generators/project/schema.json index 25cd6672..de87a018 100644 --- a/packages/nx-spring-boot/src/generators/project/schema.json +++ b/packages/nx-spring-boot/src/generators/project/schema.json @@ -200,7 +200,7 @@ "keepProjectLevelWrapper": { "description": "Keep the `Maven` or `Gradle` wrapper files from child project (when generating a multi-module project). Follow this guide https://t.ly/yvsp1 for more information.", "type": "boolean", - "default": false + "default": true }, "springInitializerUrl": { "type": "string",