UNPKG

@nxrocks/nx-ktor

Version:

Nx plugin to generate, run, package, build (and more) Ktor projects inside your Nx workspace

62 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateKtorProject = generateKtorProject; const devkit_1 = require("@nx/devkit"); const node_fetch_1 = require("node-fetch"); const ktor_utils_1 = require("../../../utils/ktor-utils"); const index_1 = require("../../../index"); const common_jvm_1 = require("@nxrocks/common-jvm"); async function generateKtorProject(tree, options) { const { url: downloadUrl, params: downloadParams } = (0, ktor_utils_1.buildKtorDownloadUrl)(options); const { headers: commonHeaders, ...otherCommonOptions } = (0, common_jvm_1.getCommonHttpHeaders)(index_1.NX_KTOR_PKG, downloadUrl, options.proxyUrl); const downloadOptions = { ...otherCommonOptions, method: 'POST', body: JSON.stringify(downloadParams), headers: { ...commonHeaders, 'Content-Type': 'application/json', }, }; devkit_1.logger.info(`⬇️ Downloading Ktor project zip from : '${downloadUrl}'...`); const response = await (0, node_fetch_1.default)(downloadUrl, downloadOptions); devkit_1.logger.info(`📦 Extracting Ktor 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 { tree.write(`${options.projectRoot}/${entryPath}`, entryContent, { mode: execPermission, }); } }); } else { throw new Error((0, devkit_1.stripIndents) ` ❌ 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} Download Params: ${JSON.stringify(downloadParams)} Response status: ${response.status} Response headers: ${JSON.stringify(response.headers)} Response body: ${await response.text()} ------------------------------------------------------`); } } //# sourceMappingURL=generate-ktor-project.js.map