Comparing version 0.6.0 to 1.0.0
46
index.js
@@ -23,26 +23,32 @@ #! /usr/bin/env node | ||
function file () { | ||
var content = cc.file.apply(null, arguments) | ||
return content ? parse(content) : null | ||
var env = cc.env(name + '_') | ||
var configs = [defaults] | ||
var configFiles = [] | ||
function addConfigFile (file) { | ||
var fileConfig = cc.file(file) | ||
if (fileConfig) { | ||
configs.push(parse(fileConfig)) | ||
configFiles.push(file) | ||
} | ||
} | ||
var local = cc.find('.'+name+'rc') | ||
// which files do we look at? | ||
if (!win) | ||
[join(etc, name, 'config'), | ||
join(etc, name + 'rc')].forEach(addConfigFile) | ||
if (home) | ||
[join(home, '.config', name, 'config'), | ||
join(home, '.config', name), | ||
join(home, '.' + name, 'config'), | ||
join(home, '.' + name + 'rc')].forEach(addConfigFile) | ||
addConfigFile(cc.find('.'+name+'rc')) | ||
if (env.config) addConfigFile(env.config) | ||
if (argv.config) addConfigFile(argv.config) | ||
var env = cc.env(name + '_') | ||
return deepExtend.apply(null, [ | ||
defaults, | ||
win ? {} : file(join(etc, name, 'config')), | ||
win ? {} : file(join(etc, name + 'rc')), | ||
home ? file(join(home, '.config', name, 'config')) : {}, | ||
home ? file(join(home, '.config', name)) : {}, | ||
home ? file(join(home, '.' + name, 'config')) : {}, | ||
home ? file(join(home, '.' + name + 'rc')) : {}, | ||
file(local), | ||
local ? {config: local} : null, | ||
env.config ? file(env.config) : null, | ||
argv.config ? file(argv.config) : null, | ||
return deepExtend.apply(null, configs.concat([ | ||
env, | ||
argv | ||
]) | ||
argv, | ||
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : null, | ||
])) | ||
} | ||
@@ -49,0 +55,0 @@ |
{ | ||
"name": "rc", | ||
"version": "0.6.0", | ||
"version": "1.0.0", | ||
"description": "hardwired configuration loader", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,3 +29,12 @@ # rc | ||
If `rc` finds any config files for your app, the returned config object will have | ||
a `configs` array containing their paths: | ||
```javascript | ||
var appCfg = require('rc')(appname, conf); | ||
appCfg.configs[0] // /etc/appnamerc | ||
appCfg.configs[1] // /home/dominictarr/.config/appname | ||
appCfg.config // same as appCfg.configs[appCfg.configs.length - 1] | ||
``` | ||
## Standards | ||
@@ -32,0 +41,0 @@ |
@@ -56,2 +56,5 @@ | ||
assert.equal(commentedJSON.envOption, 42) | ||
assert.equal(commentedJSON.config, jsonrc) | ||
assert.equal(commentedJSON.configs.length, 1) | ||
assert.equal(commentedJSON.configs[0], jsonrc) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14645
218
1
150