@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
35 lines (34 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getEnvConfig = void 0;
var lodash_1 = require("lodash");
var getEnvConfig = function (config, componentName, env) {
var _a, _b;
var defaultConfig = config.components[componentName];
if (!defaultConfig) {
throw new Error("unknown component " + componentName);
}
var 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, function (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;