@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
49 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.printVariables = void 0;
const getProjectConfig_1 = require("../../config/getProjectConfig");
const utils_1 = require("./utils");
const getAllVariablesToPrint = async (config, choice) => {
var _a;
const { env, currentComponent } = await (0, utils_1.getCurrentComponentAndEnvFromChoice)(config, choice);
if (currentComponent) {
// don't print vars if dotenv is enabled
if ((_a = config.components[currentComponent].dotEnv) !== null && _a !== void 0 ? _a : true) {
return {};
}
return await (0, getProjectConfig_1.getEnvVarsResolved)(null, env, currentComponent);
}
else {
// when in a monorep and not in a subapp, merge all env vars.
// this is not 100% correct, but better than not exporting any vars at all
// so we also add prefixed variants
return await Object.keys(config.components).reduce(async (acc, componentName) => {
var _a;
// don't print vars if dotenv is enabled
if ((_a = config.components[componentName].dotEnv) !== null && _a !== void 0 ? _a : true) {
return await acc;
}
const subappvars = await (0, getProjectConfig_1.getEnvVarsResolved)(null, env, componentName);
delete subappvars["_ALL_ENV_VAR_KEYS"];
return {
...(await acc),
...subappvars,
// also add prefixed variants in case
...Object.fromEntries(Object.entries(subappvars).map(([key, value]) => [
`${(0, utils_1.sanitizeEnvVarName)(componentName.toUpperCase())}_${key}`,
value,
])),
};
}, Promise.resolve({}));
}
};
const printVariables = async (context, choice) => {
const variables = await getAllVariablesToPrint(context.config, choice);
console.log(makeExportKeyValuestring(variables));
};
exports.printVariables = printVariables;
const makeExportKeyValuestring = (variables) => (0, utils_1.makeKeyValueString)(variables, {
keyPrefix: "export ",
escapeOptions: { quoteMode: "always" },
});
//# sourceMappingURL=printVariables.js.map