UNPKG

@nxrocks/nx-spring-boot

Version:

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

65 lines 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateBootProject = generateBootProject; const devkit_1 = require("@nx/devkit"); const node_fetch_1 = require("node-fetch"); const boot_utils_1 = require("../../../utils/boot-utils"); const index_1 = require("../../../index"); const common_jvm_1 = require("@nxrocks/common-jvm"); async function generateBootProject(tree, options) { const downloadUrl = (0, boot_utils_1.buildBootDownloadUrl)(options); devkit_1.logger.info(`⬇️ Downloading Spring Boot project zip from : ${downloadUrl}...`); const response = await (0, node_fetch_1.default)(downloadUrl, (0, common_jvm_1.getCommonHttpHeaders)(index_1.NX_SPRING_BOOT_PKG, downloadUrl, options.proxyUrl)); devkit_1.logger.info(`📦 Extracting Spring Boot project zip to '${(0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, options.projectRoot)}'...`); if (response.ok) { await (0, common_jvm_1.extractFromZipStream)(response.body, (entryPath, entryContent) => { const execPermission = entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew') ? '755' : undefined; if ((0, common_jvm_1.getMavenWrapperFiles)().includes(entryPath) || (0, common_jvm_1.getGradleWrapperFiles)().includes(entryPath)) { if (options.transformIntoMultiModule) { tree.write(`${options.moduleRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } if (options.keepProjectLevelWrapper) { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } } else if (options.projectType !== 'library' || !getBootApplicationOnlyFiles(options).includes(entryPath)) { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } }); } else { throw new Error((0, devkit_1.stripIndents) ` ❌ 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} Response status: ${response.status} Response headers: ${JSON.stringify(response.headers)} Response body: ${await response.text()} ------------------------------------------------------`); } } function getBootApplicationOnlyFiles(options) { const basePath = options.packageName?.replaceAll('.', '/'); const ext = options.language === 'kotlin' ? '.kt' : options.language === 'groovy' ? '.groovy' : '.java'; return [ `src/main/resources/application.properties`, `src/main/${options.language}/${basePath}/${(0, devkit_1.names)(options.name).className}Application${ext}`, `src/test/${options.language}/${basePath}/${(0, devkit_1.names)(options.name).className}ApplicationTests${ext}`, ]; } //# sourceMappingURL=generate-boot-project.js.map