* 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)
| 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 |