Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/node-red/node_modules/config-master/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const path = require('path')
const walkBack = require('walk-back')
/**
* A convention for storing and retrieving application config. You supply a string (e.g. `'example-app'`), the libary will walk up the directory tree merging config stored for this app. The following locations are searched, with the latter taking precedence:
*
* - Any package.json, beneath the `example-app` property.
* - Any `.example-app.json` files (or a custom filename you specify).
*
* @module config-master
*/
module.exports = loadConfig
/**
* @param {string} - config name
* @param [options] {object} - options
* @param [options.startFrom] {string} - directory to begin looking for config
* @param [options.filename] {string} - config filename (defaults to `.${configName}.json`)
* @returns {Object}
* @alias module:config-master
*/
function loadConfig (configName, options) {
options = options || {}
const configFileName = options.filename || `.${configName}.json`
const startFrom = options.startFrom || process.cwd()
const configs = Array.from(configsInTree(startFrom, configFileName)).reverse()
const packageConfigs = Array.from(packageConfigsInTree(startFrom, configName)).reverse()
return Object.assign.apply(null, [ {} ].concat(packageConfigs).concat(configs))
}
function * configsInTree (startFrom, fileName) {
let file
while ((file = walkBack(startFrom, fileName))) {
yield require(file)
startFrom = path.resolve(path.dirname(file), '..')
}
}
function * packageConfigsInTree (startFrom, configName) {
let file
while ((file = walkBack(startFrom, 'package.json'))) {
let config = require(file)[configName]
if (config) yield config
startFrom = path.resolve(path.dirname(file), '..')
}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0231 ]-- |