UNPKG

@digital-ai/plugin-scaffolder-backend-module-digitalai-xlcli

Version:

xlcli custom action for @backstage/plugin-scaffolder-backend

93 lines (87 loc) 3.13 kB
'use strict'; var os = require('os'); var fs = require('fs-extra'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var os__default = /*#__PURE__*/_interopDefaultCompat(os); var fs__default = /*#__PURE__*/_interopDefaultCompat(fs); function getTempDirectory() { return os__default.default.tmpdir(); } function getPlatformSpecificXlCli() { let filename; switch (os__default.default.platform()) { case "win32": filename = "xl.exe"; break; case "darwin": // macOS case "linux": filename = "xl"; break; default: throw new Error("Unsupported platform"); } return filename; } function readValues(config, keyName) { return config.has(keyName) && config.get(keyName) !== "" ? config.getString(keyName) : ""; } function verifyReleaseConfiguration(ctx, releaseConfig) { let release; if (ctx.input.product === "xl-release") { if (!releaseConfig) { throw new Error(`daiRelease Config not found in the app-config.yaml.`); } const instanceList = releaseConfig.getOptionalConfigArray("instances")?.map((c) => ({ name: readValues(c, "name"), host: readValues(c, "host"), token: readValues(c, "token") })) || []; release = instanceList.find( (c) => c.name === ctx.input.releaseInstance ); if (!release) { throw new Error(`daiRelease Config not found for instance: ${ctx.input.releaseInstance}`); } } else { ctx.logger.info(`xl-deploy product selected, no release config needed`); } return release; } function verifyDeployConfiguration(ctx, deployConfig) { let deploy; if (ctx.input.product === "xl-deploy") { if (!deployConfig) { throw new Error(`daiDeploy Config not found in the app-config.yaml.`); } deploy = { host: readValues(deployConfig, "host"), username: readValues(deployConfig, "username"), password: readValues(deployConfig, "password") }; } else { ctx.logger.info(`xl-release product selected, no deploy config needed`); } return deploy; } function getXlcliBinaryPath(ctx, xlcliConfig, backendConfig) { let xlcliBinaryPath = xlcliConfig?.getOptionalString("binaryPath"); if (!xlcliBinaryPath) { const downloadPath = backendConfig?.getOptionalString("workingDirectory") || getTempDirectory(); xlcliBinaryPath = `${downloadPath}/${getPlatformSpecificXlCli()}`; if (!fs__default.default.existsSync(xlcliBinaryPath)) { ctx.logger.info( `xlcli binary path not set in app-config.yaml and not found in auto-download path (${xlcliBinaryPath}) => falling back to "xl-cli" in the system PATH` ); xlcliBinaryPath = getPlatformSpecificXlCli(); } } return xlcliBinaryPath; } exports.getPlatformSpecificXlCli = getPlatformSpecificXlCli; exports.getTempDirectory = getTempDirectory; exports.getXlcliBinaryPath = getXlcliBinaryPath; exports.readValues = readValues; exports.verifyDeployConfiguration = verifyDeployConfiguration; exports.verifyReleaseConfiguration = verifyReleaseConfiguration; //# sourceMappingURL=util.cjs.js.map