UNPKG

@catladder/pipeline

Version:

Panter workflow for cloud CI/CD and DevOps

73 lines (72 loc) 2.81 kB
"use strict"; var __read = this && this.__read || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = this && this.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllEnvsByTrigger = exports.getAllEnvsInAllComponents = exports.getAllEnvs = void 0; var types_1 = require("../types"); var getConfiguredAndDefaultEnvs = function (config, componentName, envTypes) { var _a, _b; var configuredEnvs = (_a = config.components[componentName].env) !== null && _a !== void 0 ? _a : {}; // the default envs have the same name as the env types // these can be disabled with settimg them to `false` // this is the list of all not disabled envs. These are always returned var enabledDefaultEnvs = envTypes.filter(function (e) { return configuredEnvs[e] !== false; }); var configuredCustomEnvs = Object.entries((_b = config.components[componentName].env) !== null && _b !== void 0 ? _b : {}).filter(function (_a) { var _b = __read(_a, 2), config = _b[1]; return config && "type" in config && config.type && envTypes.includes(config.type); }).map(function (_a) { var _b = __read(_a, 1), envName = _b[0]; return envName; }); return __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(enabledDefaultEnvs), false), __read(configuredCustomEnvs), false))), false); }; var getAllEnvs = function (config, componentName) { return getConfiguredAndDefaultEnvs(config, componentName, types_1.DEFAULT_ENV_TYPES); }; exports.getAllEnvs = getAllEnvs; var getAllEnvsInAllComponents = function (config) { return __spreadArray([], __read(new Set(Object.keys(config.components).flatMap(function (c) { return (0, exports.getAllEnvs)(config, c); }))), false); }; exports.getAllEnvsInAllComponents = getAllEnvsInAllComponents; var getAllEnvsByTrigger = function (config, componentName, trigger) { var envTypesByTrigger = (0, types_1.getEnvTypesByTrigger)(trigger); return getConfiguredAndDefaultEnvs(config, componentName, envTypesByTrigger); }; exports.getAllEnvsByTrigger = getAllEnvsByTrigger;