UNPKG

@storm-software/config-tools

Version:

⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.

80 lines (67 loc) 4.38 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkDLO4KL2Zcjs = require('./chunk-DLO4KL2Z.cjs'); var _chunk6LIPH2JWcjs = require('./chunk-6LIPH2JW.cjs'); var _chunkE5AUC34Gcjs = require('./chunk-E5AUC34G.cjs'); var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs'); // src/config-file/get-config-file.ts var _c12 = require('c12'); var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu); var getConfigFileByName = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (fileName, filePath, options = {}) => { const workspacePath = filePath || _chunk6LIPH2JWcjs.findWorkspaceRoot.call(void 0, filePath); const configs = await Promise.all([ _c12.loadConfig.call(void 0, { cwd: workspacePath, packageJson: true, name: fileName, envName: _optionalChain([fileName, 'optionalAccess', _ => _.toUpperCase, 'call', _2 => _2()]), jitiOptions: { debug: false, fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunkE5AUC34Gcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti") }, ...options }), _c12.loadConfig.call(void 0, { cwd: workspacePath, packageJson: true, name: fileName, envName: _optionalChain([fileName, 'optionalAccess', _3 => _3.toUpperCase, 'call', _4 => _4()]), jitiOptions: { debug: false, fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunkE5AUC34Gcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti") }, configFile: fileName, ...options }) ]); return _defu2.default.call(void 0, _nullishCoalesce(configs[0], () => ( {})), _nullishCoalesce(configs[1], () => ( {}))); }, "getConfigFileByName"); var getConfigFile = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (filePath, additionalFileNames = []) => { const workspacePath = filePath ? filePath : _chunk6LIPH2JWcjs.findWorkspaceRoot.call(void 0, filePath); const result = await getConfigFileByName("storm-workspace", workspacePath); let config = result.config; const configFile = result.configFile; if (config && configFile && Object.keys(config).length > 0 && !config.skipConfigLogging) { _chunkDLO4KL2Zcjs.writeTrace.call(void 0, `Found Storm configuration file "${configFile.includes(`${workspacePath}/`) ? configFile.replace(`${workspacePath}/`, "") : configFile}" at "${workspacePath}"`, { logLevel: "all" }); } if (additionalFileNames && additionalFileNames.length > 0) { const results = await Promise.all(additionalFileNames.map((fileName) => getConfigFileByName(fileName, workspacePath))); for (const result2 of results) { if (_optionalChain([result2, 'optionalAccess', _5 => _5.config]) && _optionalChain([result2, 'optionalAccess', _6 => _6.configFile]) && Object.keys(result2.config).length > 0) { if (!config.skipConfigLogging && !result2.config.skipConfigLogging) { _chunkDLO4KL2Zcjs.writeTrace.call(void 0, `Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, { logLevel: "all" }); } config = _defu2.default.call(void 0, _nullishCoalesce(result2.config, () => ( {})), _nullishCoalesce(config, () => ( {}))); } } } if (!config) { return void 0; } config.configFile = configFile; return config; }, "getConfigFile"); exports.getConfigFileByName = getConfigFileByName; exports.getConfigFile = getConfigFile;