UNPKG

@storm-software/config-tools

Version:

A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.

93 lines (82 loc) 4.36 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 _chunk3CNCDDWZcjs = require('./chunk-3CNCDDWZ.cjs'); var _chunkDLJF3QQScjs = require('./chunk-DLJF3QQS.cjs'); var _chunkBDATZ3UBcjs = require('./chunk-BDATZ3UB.cjs'); // src/config-file/get-config-file.ts var _c12 = require('c12'); var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu); var getConfigFileByName = async (fileName, filePath, options = {}) => { const workspacePath = filePath || _chunk3CNCDDWZcjs.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 : _chunkBDATZ3UBcjs.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 : _chunkBDATZ3UBcjs.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], () => ( {}))); }; var getConfigFile = async (filePath, additionalFileNames = []) => { const workspacePath = filePath ? filePath : _chunk3CNCDDWZcjs.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) { _chunkDLJF3QQScjs.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) { _chunkDLJF3QQScjs.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 || Object.keys(config).length === 0) { return void 0; } config.configFile = configFile; return config; }; exports.getConfigFileByName = getConfigFileByName; exports.getConfigFile = getConfigFile;