-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix
mvnw
or gradlew
no longer generated when creating simple…
… projects
- Loading branch information
Showing
19 changed files
with
652 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 134 additions & 80 deletions
214
packages/nx-ktor/src/generators/project/lib/prompt-multi-module-support.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, `<!-- ${helpComment} -->`); | ||
} | ||
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, | ||
`<!-- ${helpComment} -->` | ||
); | ||
} 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' | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.