MCPcopy Index your code
hub / github.com/node-config/node-config / loadFileConfigs

Method loadFileConfigs

lib/util.js:310–369  ·  view source on GitHub ↗

* Load the individual file configurations. * * * This method builds a map of filename to the configuration object defined * by the file. The search order is: * * * * default.EXT * (deployment).EXT * (hostname).EXT * (hostname)-(deployment).EXT

(opts)

Source from the content-addressed store, hash-verified

308 * @return {Load} loadConfig
309 */
310 static loadFileConfigs(opts) {
311 let load;
312
313 if (opts instanceof Load) {
314 load = opts;
315 } else {
316 load = new Load(opts);
317 }
318
319 let options = load.options;
320 let dir = options.configDir;
321 dir = _toAbsolutePath(dir);
322
323 // Read each file in turn
324 const baseNames = ['default'].concat(options.nodeEnv);
325 const hostName = options.hostName;
326
327 // #236: Also add full hostname when they are different.
328 if (hostName) {
329 const firstDomain = hostName.split('.')[0];
330
331 for (let env of options.nodeEnv) {
332 // Backward compatibility
333 baseNames.push(firstDomain, firstDomain + '-' + env);
334
335 // Add full hostname when it is not the same
336 if (hostName !== firstDomain) {
337 baseNames.push(hostName, hostName + '-' + env);
338 }
339 }
340 }
341
342 for (let env of options.nodeEnv) {
343 baseNames.push('local', 'local-' + env);
344 }
345
346 const allowedFiles = {};
347 let resolutionIndex = 1;
348 const extNames = options.parser.getFilesOrder();
349
350 for (let baseName of baseNames) {
351 const fileNames = [baseName];
352 if (options.appInstance) {
353 fileNames.push(baseName + '-' + options.appInstance);
354 }
355
356 for (let fileName of fileNames) {
357 for (let extName of extNames) {
358 allowedFiles[fileName + '.' + extName] = resolutionIndex++;
359 }
360 }
361 }
362
363 const locatedFiles = this.locateMatchingFiles(dir, allowedFiles);
364 for (let fullFilename of locatedFiles) {
365 load.loadFile(fullFilename);
366 }
367

Callers 7

scanMethod · 0.45
util.jsFile · 0.45
0-util.jsFile · 0.45
config.tsFile · 0.45
util.tsFile · 0.45
index.jsFile · 0.45

Calls 3

locateMatchingFilesMethod · 0.95
_toAbsolutePathFunction · 0.85
loadFileMethod · 0.80

Tested by

no test coverage detected