@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
35 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeEnvVarName = exports.makeKeyValueString = exports.getCurrentComponentAndEnvFromChoice = exports.getComponentFullPath = void 0;
const path_1 = require("path");
const projects_1 = require("../../utils/projects");
const pipeline_1 = require("../../../../pipeline/src/index.js");
const getComponentFullPath = (gitRoot, config, componentName) => {
return (0, path_1.join)(gitRoot, config.components[componentName].dir);
};
exports.getComponentFullPath = getComponentFullPath;
const getCurrentComponentName = async (config) => {
const gitRoot = await (0, projects_1.getGitRoot)();
const currentDir = process.cwd();
return Object.keys(config.components).find((c) => currentDir.startsWith((0, exports.getComponentFullPath)(gitRoot, config, c)));
};
const getCurrentComponentAndEnvFromChoice = async (config, choice) => {
var _a, _b;
const env = (_a = choice === null || choice === void 0 ? void 0 : choice.env) !== null && _a !== void 0 ? _a : "local";
const currentComponent = (_b = choice === null || choice === void 0 ? void 0 : choice.componentName) !== null && _b !== void 0 ? _b : (await getCurrentComponentName(config));
return {
currentComponent,
env,
};
};
exports.getCurrentComponentAndEnvFromChoice = getCurrentComponentAndEnvFromChoice;
const makeKeyValueString = (variables, { keyPrefix, escapeOptions } = {
keyPrefix: "",
}) => Object.entries(variables)
// quotes are important, otherwise line breaks don't work properly
.map(([key, value]) => `${keyPrefix}${key}=${(0, pipeline_1.escapeForDotEnv)(value, escapeOptions)}`)
.join("\n");
exports.makeKeyValueString = makeKeyValueString;
const sanitizeEnvVarName = (name) => name.replace(/[\s\-.]+/g, "_");
exports.sanitizeEnvVarName = sanitizeEnvVarName;
//# sourceMappingURL=utils.js.map