UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

34 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnvConfig = void 0; const lodash_1 = require("lodash"); const getEnvConfig = (config, componentName, env) => { var _a, _b; const defaultConfig = config.components[componentName]; if (!defaultConfig) { throw new Error("unknown component " + componentName); } const envCustomizations = (_b = (_a = defaultConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {}; if (envCustomizations === false) { // env is disabled, still return the default config return defaultConfig; } /** * env config is merged with default. Arrays are not merged. * you can customize this by providing a function that takes the default value as argument */ return (0, lodash_1.mergeWith)( // mergeWith unfortunatly mutates the first object, so we need to clone it. // Passing empty object also doesn't work for us, because that will mess with the customizer function (second argument isn't nessecary the customized value) (0, lodash_1.cloneDeep)(defaultConfig), envCustomizations, (defaultValue, customValue, key, obj, source) => { // check if custom value is a function (and default is not), // we currently don't have config options, that are functions, but we might in the future (customJobs is an exception) if (typeof customValue === "function" && typeof defaultValue !== "function") { return customValue(defaultValue); } return undefined; }); }; exports.getEnvConfig = getEnvConfig; //# sourceMappingURL=getEnvConfig.js.map