@nxrocks/nx-spring-boot
Version:
Nx Plugin to generate, run, package, build (and more) Spring Boot projects inside your Nx workspace
89 lines • 5.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptForMultiModuleSupport = promptForMultiModuleSupport;
const devkit_1 = require("@nx/devkit");
const enquirer_1 = require("enquirer");
const common_jvm_1 = require("@nxrocks/common-jvm");
async function promptForMultiModuleSupport(tree, options) {
if ((options.transformIntoMultiModule === undefined ||
options.addToExistingParentModule === undefined) &&
options.parentModuleName === undefined &&
process.env.NX_INTERACTIVE === 'true') {
devkit_1.logger.info(`⏳ Checking for existing multi-module projects. Please wait...`);
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
const multiModuleProjects = Object.values(projectGraph.nodes)
.map((n) => n.data)
.filter((project) => options.buildSystem === 'maven-project'
? (0, common_jvm_1.hasMultiModuleMavenProjectInTree)(tree, project.root)
: (0, common_jvm_1.hasMultiModuleGradleProjectInTree)(tree, project.root));
const buildSystemName = options.buildSystem === 'maven-project' ? 'Maven' : 'Gradle';
if (multiModuleProjects.length === 0) {
options.transformIntoMultiModule = await (0, enquirer_1.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 (0, enquirer_1.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 = !options.transformIntoMultiModule;
}
else {
options.addToExistingParentModule = await (0, enquirer_1.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 (0, enquirer_1.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 = !options.addToExistingParentModule;
}
}
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 (0, common_jvm_1.getAdjustedProjectAndModuleRoot)(options, isMavenProject);
options.projectRoot = opts.projectRoot;
options.moduleRoot = opts.moduleRoot;
if (options.transformIntoMultiModule) {
// add the root module
if (isMavenProject) {
(0, common_jvm_1.initMavenParentModule)(tree, options.moduleRoot, options.groupId, options.parentModuleName, options.projectName, `<!-- ${helpComment} -->`);
}
else {
(0, common_jvm_1.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) {
(0, common_jvm_1.addMavenModule)(tree, options.moduleRoot, options.projectName);
}
else {
(0, common_jvm_1.addGradleModule)(tree, options.moduleRoot, options.projectName, opts.offsetFromRoot, options.buildSystem === 'gradle-project-kotlin');
}
}
}
}
//# sourceMappingURL=prompt-multi-module-support.js.map