UNPKG

@nxrocks/nx-quarkus

Version:

Nx Plugin to generate, run, package, build (and more) Quarkus projects inside your Nx workspace

91 lines 5.31 kB
"use strict"; 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) { const buildSystemName = options.buildSystem === 'MAVEN' ? 'Maven' : 'Gradle'; 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' ? (0, common_jvm_1.hasMultiModuleMavenProjectInTree)(tree, project.root) : (0, common_jvm_1.hasMultiModuleGradleProjectInTree)(tree, project.root)); 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: '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 = !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 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 (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_KOTLIN_DSL', `// ${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_KOTLIN_DSL'); } } } } //# sourceMappingURL=prompt-multi-module-support.js.map