UNPKG

@kosko/cli

Version:

Organize Kubernetes manifests in JavaScript.

46 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupEnv = void 0; const require_1 = require("./require.js"); const require_2 = require("@kosko/require"); const set_option_1 = require("./set-option.js"); const KOSKO_ENV = "@kosko/env"; function excludeFalsyInArray(input) { return input.filter(Boolean); } function pickEnvArray(envs) { if (envs.length > 1) return envs; return envs[0]; } async function setupEnv(config, args) { var _a; const cwd = args.cwd; const envs = [await require_1.localRequireDefault(KOSKO_ENV, cwd)]; if (await require_2.isESMSupported()) { // Why `@kosko/env` package has to be imported twice? Because the cache on // CommonJS and ESM are separated, which means we have two isolated // instances of `Environment`, and each of them must be initialized // in order to make sure users can access the environment in both CommonJS // and ESM environment. envs.push(await require_1.localImportDefault(KOSKO_ENV, cwd)); } const paths = ((_a = config.paths) === null || _a === void 0 ? void 0 : _a.environment) || {}; const setReducer = args.set && args.set.length ? set_option_1.createCLIEnvReducer(args.set) : undefined; // Initialize all environments for (const env of envs) { env.cwd = cwd; env.env = pickEnvArray(excludeFalsyInArray([config.baseEnvironment, args.env])); if (config.extensions) env.extensions = [...config.extensions]; if (paths.global) env.paths.global = paths.global; if (paths.component) env.paths.component = paths.component; if (setReducer) { env.setReducers((reducers) => [...reducers, setReducer]); } } } exports.setupEnv = setupEnv; //# sourceMappingURL=env.js.map