@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
67 lines (66 loc) • 2.31 kB
JavaScript
;
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;
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.componentContextNeedsBuildTimeDotEnv = exports.writeDotEnv = void 0;
var lodash_1 = require("lodash");
var bashEscape_1 = require("../../bash/bashEscape");
var getBuildInfoVariables_1 = require("../../context/getBuildInfoVariables");
var gitlab_1 = require("../../utils/gitlab");
/**
* writes a .env file in the components folder
* @param context
* @returns
*/
var writeDotEnv = function (context) {
var envVars = context.environment.envVars;
// make key=value and sanitize multiline
var keyValueString = Object.entries(envVars)
// filter out null and undefined values
.filter(function (_a) {
var _b = __read(_a, 2),
value = _b[1];
return !(0, lodash_1.isNil)(value);
})
// filter out build variables, since they may interfer with caching like turbo
// build variables are rarely used anyway and we may treat them differently in the future
.filter(function (_a) {
var _b = __read(_a, 1),
key = _b[0];
return !getBuildInfoVariables_1.ALL_BUILD_VARIABLES.includes(key);
}).map(function (_a) {
var _b = __read(_a, 2),
key = _b[0],
value = _b[1];
return "".concat(key, "=").concat((0, bashEscape_1.escapeForDotEnv)(value));
}).join("\n");
return (0, gitlab_1.collapseableSection)("write-dotenv-" + context.name, "write dot env for " + context.name)(["cat <<EOF > ".concat(context.build.dir, "/.env\n").concat(keyValueString, "\nEOF")]);
};
exports.writeDotEnv = writeDotEnv;
var componentContextNeedsBuildTimeDotEnv = function (context) {
var _a;
return ((_a = context.componentConfig.dotEnv) !== null && _a !== void 0 ? _a : true) === true; // don't build when set to `local`
};
exports.componentContextNeedsBuildTimeDotEnv = componentContextNeedsBuildTimeDotEnv;