@digital-ai/plugin-scaffolder-backend-module-digitalai-xlcli
Version:
xlcli custom action for @backstage/plugin-scaffolder-backend
73 lines (67 loc) • 2.6 kB
JavaScript
;
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
var path = require('path');
var util = require('./util.cjs.js');
var schema = require('./schema.cjs.js');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
const xlcliApplyAction = (releaseConfig, deployConfig, xlcliConfig, backendConfig) => {
return pluginScaffolderNode.createTemplateAction({
id: "digitalai:xlcli:apply",
schema: {
input: schema.xlcliInputSchema
},
async handler(ctx) {
const deploy = util.verifyDeployConfiguration(ctx, deployConfig);
const release = util.verifyReleaseConfiguration(ctx, releaseConfig);
ctx.logger.info(`Workspace: "${ctx.workspacePath}"`);
const envVars = {
...process.env
};
const xlcliBinaryPath = util.getXlcliBinaryPath(ctx, xlcliConfig, backendConfig);
ctx.logger.info(`xlcli binary path: ${xlcliBinaryPath}`);
const initArgs = [
"apply",
"-f",
ctx.input.filePath
];
console.log("input.product:", ctx.input.product);
if (ctx.input.product === "xl-deploy") {
if (deploy) {
initArgs.push(
"--xl-deploy-url",
deploy?.host,
"--xl-deploy-username",
deploy?.username,
"--xl-deploy-password",
deploy?.password
);
ctx.output("url", `${deploy.host}/#/explorer`);
}
} else if (ctx.input.product === "xl-release") {
if (release) {
initArgs.push("--xl-release-url", release.host, "--xl-release-token", release.token);
ctx.output("url", `${release.host}/#/templates?has_filter`);
}
}
await pluginScaffolderNode.executeShellCommand({
command: xlcliBinaryPath,
args: initArgs,
logger: ctx.logger,
options: {
cwd: path__default.default.resolve(ctx.workspacePath),
env: envVars
}
});
if (ctx.input.product === "xl-deploy") {
if (deploy)
ctx.logger.info(`...Finished applying "${ctx.input.filePath}" in xl-deploy. URL: ${deploy?.host}/#/explorer`);
} else if (ctx.input.product === "xl-release") {
if (release)
ctx.logger.info(`...Finished applying "${ctx.input.filePath}" in xl-release. URL: ${release.host}/#/templates?has_filter`);
}
}
});
};
exports.xlcliApplyAction = xlcliApplyAction;
//# sourceMappingURL=xlcli-apply.cjs.js.map