Browse files

rename to config-chain, add find function, bump version 0.1

  • Loading branch information...
1 parent 2397fbb commit a586bec5180a9bdac60225cb5e01c6e738a89081 @dominictarr committed Nov 5, 2011
Showing with 87 additions and 331 deletions.
  1. +22 −0 LICENCE
  2. +17 −0 index.js
  3. +0 −319 npm-debug.log
  4. +3 −3 package.json
  5. +32 −9 readme.markdown
  6. +13 −0 test/find-file.js
View
22 LICENCE
@@ -0,0 +1,22 @@
+Copyright (c) 2011 Dominic Tarr
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
17 index.js
@@ -17,6 +17,23 @@ var exports = module.exports = function () {
return conf
}
+//recursively find a file...
+
+var find = exports.find = function () {
+ var rel = path.join.apply(null, [].slice.call(arguments))
+
+ function find(start, rel) {
+ var file = path.join(start, rel)
+ try {
+ fs.statSync(file)
+ return file
+ } catch (err) {
+ if(start != '/')
+ return find(path.dirname(start), rel)
+ }
+ }
+ return find(__dirname, rel)
+}
var json = exports.json = function () {
var file = path.join.apply(null, [].slice.call(arguments))
View
319 npm-debug.log
@@ -1,319 +0,0 @@
-info it worked if it ends with ok
-verbose cli [ 'node', '/usr/local/bin/npm', 'publish' ]
-info using npm@1.0.27
-info using node@v0.4.10
-verbose config file /home/dominic/.npmrc
-verbose config file /usr/local/etc/npmrc
-verbose publish [ '.' ]
-silly testEngine { name: 'configurator',
-silly testEngine version: '0.0.0',
-silly testEngine description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly testEngine homepage: 'http://github.com/dominictarr/configurator',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/dominictarr/configurator.git' },
-silly testEngine dependencies: { 'proto-list': '1' },
-silly testEngine author:
-silly testEngine { name: 'Dominic Tarr',
-silly testEngine email: 'dominic.tarr@gmail.com',
-silly testEngine url: 'http://bit.ly/dominictarr' },
-silly testEngine scripts: { test: 'meta-test test/*.js' },
-silly testEngine _npmJsonOpts:
-silly testEngine { file: '/home/dominic/source/dev/configurator/package.json',
-silly testEngine wscript: false,
-silly testEngine contributors: false,
-silly testEngine serverjs: false },
-silly testEngine _id: 'configurator@0.0.0',
-silly testEngine devDependencies: {},
-silly testEngine engines: { node: '*' },
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.27',
-silly testEngine _nodeVersion: 'v0.4.10',
-silly testEngine _defaultsLoaded: true }
-verbose caching /home/dominic/source/dev/configurator/package.json
-verbose loadDefaults configurator@0.0.0
-info prepublish configurator@0.0.0
-verbose cache add [ '.', null ]
-silly cache add: name, spec, args [ undefined, '.', [ '.', null ] ]
-verbose parsed url { pathname: '.', href: '.' }
-silly testEngine { name: 'configurator',
-silly testEngine version: '0.0.0',
-silly testEngine description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly testEngine homepage: 'http://github.com/dominictarr/configurator',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/dominictarr/configurator.git' },
-silly testEngine dependencies: { 'proto-list': '1' },
-silly testEngine author:
-silly testEngine { name: 'Dominic Tarr',
-silly testEngine email: 'dominic.tarr@gmail.com',
-silly testEngine url: 'http://bit.ly/dominictarr' },
-silly testEngine scripts: { test: 'meta-test test/*.js' },
-silly testEngine _npmJsonOpts:
-silly testEngine { file: 'package.json',
-silly testEngine wscript: false,
-silly testEngine contributors: false,
-silly testEngine serverjs: false },
-silly testEngine _id: 'configurator@0.0.0',
-silly testEngine devDependencies: {},
-silly testEngine engines: { node: '*' },
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.27',
-silly testEngine _nodeVersion: 'v0.4.10',
-silly testEngine _defaultsLoaded: true,
-silly testEngine path: '/home/dominic/source/dev/configurator',
-silly testEngine bundleDependencies: [] }
-verbose caching package.json
-verbose loadDefaults configurator@0.0.0
-verbose pack /home/dominic/source/dev/configurator /tmp/npm-1314793254996/1314793254995-0.8771079538855702/tmp.tgz
-verbose mkdir (expected) error ENOENT, No such file or directory '/tmp/npm-1314793254996'
-verbose mkdir (expected) error ENOENT, No such file or directory '/tmp/npm-1314793254996/1314793254995-0.8771079538855702'
-verbose mkdir done: /tmp/npm-1314793254996/1314793254995-0.8771079538855702 755
-verbose mkdir'ed /tmp/npm-1314793254996/1314793254995-0.8771079538855702
-verbose tar about to write tar and gzip it.
-silly tar args [ '-cvf',
-silly tar args '-',
-silly tar args 'configurator/index.js',
-silly tar args 'configurator/package.json',
-silly tar args 'configurator/readme.markdown',
-silly tar args 'configurator/.gitignore' ]
-verbose success tar -cvf - <file list elided>
-verbose success gzip "--stdout"
-verbose mkdir (expected) error ENOENT, No such file or directory '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents'
-verbose mkdir (expected) error ENOENT, No such file or directory '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm'
-verbose mkdir done: /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm 755
-verbose unpack_ uid, gid [ undefined, undefined ]
-verbose unpackTarget /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package
-silly gunzTarPerm modes [ '755', '644' ]
-verbose success gzip "--decompress" "--stdout" "/tmp/npm-1314793254996/1314793254995-0.8771079538855702/tmp.tgz"
-verbose success tar "-mvxpf" "-" "-o" "-C" "/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm"
-silly asyncMap in gTP /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator/
-silly asyncMap in gTP /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator/index.js
-silly asyncMap in gTP /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator/package.json
-silly asyncMap in gTP /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator/readme.markdown
-silly asyncMap in gTP /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator/.gitignore
-verbose gunzed /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator
-verbose rm'ed /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package
-verbose renamed [ '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/___package.npm/configurator',
-verbose renamed '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package' ]
-silly testEngine { name: 'configurator',
-silly testEngine version: '0.0.0',
-silly testEngine description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly testEngine homepage: 'http://github.com/dominictarr/configurator',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/dominictarr/configurator.git' },
-silly testEngine dependencies: { 'proto-list': '1' },
-silly testEngine author:
-silly testEngine { name: 'Dominic Tarr',
-silly testEngine email: 'dominic.tarr@gmail.com',
-silly testEngine url: 'http://bit.ly/dominictarr' },
-silly testEngine scripts: { test: 'meta-test test/*.js' },
-silly testEngine _npmJsonOpts:
-silly testEngine { file: '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package/package.json',
-silly testEngine wscript: false,
-silly testEngine contributors: false,
-silly testEngine serverjs: false },
-silly testEngine _id: 'configurator@0.0.0',
-silly testEngine devDependencies: {},
-silly testEngine engines: { node: '*' },
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.27',
-silly testEngine _nodeVersion: 'v0.4.10',
-silly testEngine _defaultsLoaded: true,
-silly testEngine path: '/tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package' }
-verbose caching /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package/package.json
-verbose loadDefaults configurator@0.0.0
-verbose tarball contents [ 'package' ]
-verbose from cache /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package/package.json
-verbose pack /tmp/npm-1314793254996/1314793254995-0.8771079538855702/contents/package /home/dominic/.npm/configurator/0.0.0/package.tgz
-verbose mkdir (expected) error ENOENT, No such file or directory '/home/dominic/.npm/configurator'
-verbose mkdir (expected) error ENOENT, No such file or directory '/home/dominic/.npm/configurator/0.0.0'
-verbose mkdir done: /home/dominic/.npm/configurator/0.0.0 755
-verbose mkdir'ed /home/dominic/.npm/configurator/0.0.0
-verbose tar about to write tar and gzip it.
-silly tar args [ '-cvf',
-silly tar args '-',
-silly tar args 'package/index.js',
-silly tar args 'package/package.json',
-silly tar args 'package/readme.markdown',
-silly tar args 'package/.gitignore' ]
-verbose success tar -cvf - <file list elided>
-verbose success gzip "--stdout"
-verbose mkdir (expected) error ENOENT, No such file or directory '/home/dominic/.npm/configurator/0.0.0/___package.npm'
-verbose mkdir done: /home/dominic/.npm/configurator/0.0.0/___package.npm 755
-verbose unpack_ uid, gid [ undefined, undefined ]
-verbose unpackTarget /home/dominic/.npm/configurator/0.0.0/package
-silly gunzTarPerm modes [ '755', '644' ]
-verbose success gzip "--decompress" "--stdout" "/home/dominic/.npm/configurator/0.0.0/package.tgz"
-verbose success tar "-mvxpf" "-" "-o" "-C" "/home/dominic/.npm/configurator/0.0.0/___package.npm"
-silly asyncMap in gTP /home/dominic/.npm/configurator/0.0.0/___package.npm/package/
-silly asyncMap in gTP /home/dominic/.npm/configurator/0.0.0/___package.npm/package/index.js
-silly asyncMap in gTP /home/dominic/.npm/configurator/0.0.0/___package.npm/package/package.json
-silly asyncMap in gTP /home/dominic/.npm/configurator/0.0.0/___package.npm/package/readme.markdown
-silly asyncMap in gTP /home/dominic/.npm/configurator/0.0.0/___package.npm/package/.gitignore
-verbose gunzed /home/dominic/.npm/configurator/0.0.0/___package.npm/package
-verbose rm'ed /home/dominic/.npm/configurator/0.0.0/package
-verbose renamed [ '/home/dominic/.npm/configurator/0.0.0/___package.npm/package',
-verbose renamed '/home/dominic/.npm/configurator/0.0.0/package' ]
-silly testEngine { name: 'configurator',
-silly testEngine version: '0.0.0',
-silly testEngine description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly testEngine homepage: 'http://github.com/dominictarr/configurator',
-silly testEngine repository:
-silly testEngine { type: 'git',
-silly testEngine url: 'git://github.com/dominictarr/configurator.git' },
-silly testEngine dependencies: { 'proto-list': '1' },
-silly testEngine author:
-silly testEngine { name: 'Dominic Tarr',
-silly testEngine email: 'dominic.tarr@gmail.com',
-silly testEngine url: 'http://bit.ly/dominictarr' },
-silly testEngine scripts: { test: 'meta-test test/*.js' },
-silly testEngine _npmJsonOpts:
-silly testEngine { file: '/home/dominic/.npm/configurator/0.0.0/package/package.json',
-silly testEngine wscript: false,
-silly testEngine contributors: false,
-silly testEngine serverjs: false },
-silly testEngine _id: 'configurator@0.0.0',
-silly testEngine devDependencies: {},
-silly testEngine engines: { node: '*' },
-silly testEngine _engineSupported: true,
-silly testEngine _npmVersion: '1.0.27',
-silly testEngine _nodeVersion: 'v0.4.10',
-silly testEngine _defaultsLoaded: true,
-silly testEngine dist:
-silly testEngine { shasum: '705bfbeeb0a123cd45c3f9f636bc39ccada0de2b',
-silly testEngine tarball: 'http://registry.npmjs.org/configurator/-/configurator-0.0.0.tgz' } }
-verbose caching /home/dominic/.npm/configurator/0.0.0/package/package.json
-verbose loadDefaults configurator@0.0.0
-silly updated sha bytes 1368
-info shasum 705bfbeeb0a123cd45c3f9f636bc39ccada0de2b
-info shasum /home/dominic/.npm/configurator/0.0.0/package.tgz
-verbose from cache /home/dominic/.npm/configurator/0.0.0/package/package.json
-verbose chmod /home/dominic/.npm/configurator/0.0.0/package.tgz 644
-silly publish { name: 'configurator',
-silly publish version: '0.0.0',
-silly publish description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly publish homepage: 'http://github.com/dominictarr/configurator',
-silly publish repository:
-silly publish { type: 'git',
-silly publish url: 'git://github.com/dominictarr/configurator.git' },
-silly publish dependencies: { 'proto-list': '1' },
-silly publish author:
-silly publish { name: 'Dominic Tarr',
-silly publish email: 'dominic.tarr@gmail.com',
-silly publish url: 'http://bit.ly/dominictarr' },
-silly publish scripts: { test: 'meta-test test/*.js' },
-silly publish _npmJsonOpts:
-silly publish { file: '/home/dominic/.npm/configurator/0.0.0/package/package.json',
-silly publish wscript: false,
-silly publish contributors: false,
-silly publish serverjs: false },
-silly publish _id: 'configurator@0.0.0',
-silly publish devDependencies: {},
-silly publish engines: { node: '*' },
-silly publish _engineSupported: true,
-silly publish _npmVersion: '1.0.27',
-silly publish _nodeVersion: 'v0.4.10',
-silly publish _defaultsLoaded: true,
-silly publish dist:
-silly publish { shasum: '705bfbeeb0a123cd45c3f9f636bc39ccada0de2b',
-silly publish tarball: 'http://registry.npmjs.org/configurator/-/configurator-0.0.0.tgz' } }
-verbose PUT configurator
-verbose raw, before any munging configurator
-verbose url resolving [ 'https://registry.npmjs.org/', './configurator' ]
-verbose url resolved https://registry.npmjs.org/configurator
-verbose url parsed { protocol: 'https:',
-verbose url parsed slashes: true,
-verbose url parsed host: 'registry.npmjs.org',
-verbose url parsed hostname: 'registry.npmjs.org',
-verbose url parsed href: 'https://registry.npmjs.org/configurator',
-verbose url parsed pathname: '/configurator' }
-silly writing json { _id: 'configurator',
-silly writing json name: 'configurator',
-silly writing json description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly writing json 'dist-tags': {},
-silly writing json versions: {},
-silly writing json maintainers:
-silly writing json [ { name: 'dominictarr',
-silly writing json email: 'dominic.tarr@gmail.com' } ] }
-verbose response https://registry.npmjs.org/configurator
-silly chunk {"error":"conflict","reason":"Document update conflict."}
-silly chunk
-verbose GET configurator
-verbose raw, before any munging configurator
-verbose url resolving [ 'https://registry.npmjs.org/', './configurator' ]
-verbose url resolved https://registry.npmjs.org/configurator
-verbose url parsed { protocol: 'https:',
-verbose url parsed slashes: true,
-verbose url parsed host: 'registry.npmjs.org',
-verbose url parsed hostname: 'registry.npmjs.org',
-verbose url parsed href: 'https://registry.npmjs.org/configurator',
-verbose url parsed pathname: '/configurator' }
-verbose response https://registry.npmjs.org/configurator
-silly chunk {"_id":"configurator","_rev":"5-b31ad9731741d19f28241f6af5b41fee","name":"configurator","description":"Flexible JSON based configurations with inheritence","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"configurator","description":"Flexible JSON based configurations with inheritence","version":"0.1.0","author":{"name":"Bart Teeuwisse","email":"bart@zazengo.com"},"contributors":[{"name":"Bart Teeuwisse","email":"bart@zazengo.com"}],"dependencies":{"yui3":">= 0.5.9"},"keywords":["zazengo","configuration"],"directories":{"lib":"./lib/configurator"},"engines":{"node":">= 0.2.4"},"_id":"configurator@0.1.0","_nodeSupported":true,"_npmVersion":"0.2.7-3","_nodeVersion":"v0.2.4","dist":{"tarball":"http://registry.npmjs.org/configurator/-/configurator-0.1.0.tgz"}},"0.1.1":{"name":"configurator","description":"Flexible JSON based configurations with inheritence","version":"0.1.1","author":{"name":"Bart Teeuwisse","email":"bart@zazengo.com"},"contributors":[{"name":"Bart Teeuwisse","email":"bart@zazengo.com"}],"dependencies":{"yui3":">= 0.5.9"},"keywords":["zazengo","configuration"],"directories":{"lib":"./lib/configurator"},"engines":{"node":">= 0.2.4"},"_id":"configurator@0.1.1","_nodeSupported":true,"_npmVersion":"0.2.7-3","_nodeVersion":"v0.2.4","dist":{"tarball":"http://registry.npmjs.org/configurator/-/configurator-0.1.1.tgz"}}},"maintainers":[{"name":"bartt","email":"bart@zazengo.com"}],"author":{"name":"Bart Teeuwisse","email":"bart@zazengo.com"}}
-verbose PUT configurator/0.0.0/-tag/latest
-verbose raw, before any munging configurator/0.0.0/-tag/latest
-verbose url resolving [ 'https://registry.npmjs.org/',
-verbose url resolving './configurator/0.0.0/-tag/latest' ]
-verbose url resolved https://registry.npmjs.org/configurator/0.0.0/-tag/latest
-verbose url parsed { protocol: 'https:',
-verbose url parsed slashes: true,
-verbose url parsed host: 'registry.npmjs.org',
-verbose url parsed hostname: 'registry.npmjs.org',
-verbose url parsed href: 'https://registry.npmjs.org/configurator/0.0.0/-tag/latest',
-verbose url parsed pathname: '/configurator/0.0.0/-tag/latest' }
-silly writing json { name: 'configurator',
-silly writing json version: '0.0.0',
-silly writing json description: 'HANDLE CONFIGURATION ONCE AND FOR ALL',
-silly writing json homepage: 'http://github.com/dominictarr/configurator',
-silly writing json repository:
-silly writing json { type: 'git',
-silly writing json url: 'git://github.com/dominictarr/configurator.git' },
-silly writing json dependencies: { 'proto-list': '1' },
-silly writing json author:
-silly writing json { name: 'Dominic Tarr',
-silly writing json email: 'dominic.tarr@gmail.com',
-silly writing json url: 'http://bit.ly/dominictarr' },
-silly writing json scripts: { test: 'meta-test test/*.js' },
-silly writing json _npmJsonOpts:
-silly writing json { file: '/home/dominic/.npm/configurator/0.0.0/package/package.json',
-silly writing json wscript: false,
-silly writing json contributors: false,
-silly writing json serverjs: false },
-silly writing json _id: 'configurator@0.0.0',
-silly writing json devDependencies: {},
-silly writing json engines: { node: '*' },
-silly writing json _engineSupported: true,
-silly writing json _npmVersion: '1.0.27',
-silly writing json _nodeVersion: 'v0.4.10',
-silly writing json _defaultsLoaded: true,
-silly writing json dist:
-silly writing json { shasum: '705bfbeeb0a123cd45c3f9f636bc39ccada0de2b',
-silly writing json tarball: 'http://registry.npmjs.org/configurator/-/configurator-0.0.0.tgz' } }
-verbose response https://registry.npmjs.org/configurator/0.0.0/-tag/latest
-silly chunk {"error":"forbidden","reason":"user: dominictarr not authorized to modify configurator"}
-silly chunk
-ERR! Error sending version data
-ERR! Error: forbidden user: dominictarr not authorized to modify configurator: configurator/0.0.0/-tag/latest
-ERR! at IncomingMessage.responseDone (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:205:16)
-ERR! at IncomingMessage.emit (events.js:81:20)
-ERR! at HTTPParser.onMessageComplete (http.js:133:23)
-ERR! at CleartextStream.ondata (http.js:1228:22)
-ERR! at CleartextStream._push (tls.js:303:27)
-ERR! at SecurePair.cycle (tls.js:577:20)
-ERR! at EncryptedStream.write (tls.js:96:13)
-ERR! at Socket.ondata (stream.js:36:26)
-ERR! at Socket.emit (events.js:64:17)
-ERR! at Socket._onReadable (net.js:678:14)
-ERR! Report this *entire* log at:
-ERR! <http://github.com/isaacs/npm/issues>
-ERR! or email it to:
-ERR! <npm-@googlegroups.com>
-ERR!
-ERR! System Linux 2.6.35-30-generic-pae
-ERR! command "node" "/usr/local/bin/npm" "publish"
-ERR! cwd /home/dominic/source/dev/configurator
-ERR! node -v v0.4.10
-ERR! npm -v 1.0.27
-verbose exit [ 1, true ]
View
6 package.json
@@ -1,5 +1,5 @@
-{ "name": "CONFIGURATOR"
-, "version": "0.0.0"
+{ "name": "config-chain"
+, "version": "0.1.0"
, "description": "HANDLE CONFIGURATION ONCE AND FOR ALL"
, "homepage": "http://github.com/dominictarr/configurator"
, "repository":
@@ -9,4 +9,4 @@
"proto-list": "1"
}
, "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://bit.ly/dominictarr)"
-, "scripts": { "test": "meta-test test/*.js" } }
+}
View
41 readme.markdown
@@ -1,25 +1,43 @@
-#configurator
+#config-chain
+
USE THIS MODULE TO LOAD ALL YOUR CONFIGURATIONS
``` js
- var configurator = require('CONFIGURATOR')
+ //npm install config-chain
+
+ var cc = require('config-chain')
, opts = require('optimist').argv //ALWAYS USE OPTIMIST FOR COMMAND LINE OPTIONS.
, env = opts.env || process.env.YOUR_APP_ENV || 'dev' //SET YOUR ENV LIKE THIS.
// EACH ARG TO CONFIGURATOR IS LOADED INTO CONFIGURATION CHAIN
// EARLIER ITEMS OVERIDE LATER ITEMS
// PUTS COMMAND LINE OPTS FIRST, AND DEFAULTS LAST!
+ //strings are interpereted as filenames.
+ //will be loaded synchronously
+
var conf =
- configurator(
- opts, //OVERRIDE SETTINGS WITH COMMAND LINE OPTS
- path.join(__dirname, 'config.' + env + '.json'), //FILE NAMED BY ENV
- env === 'prod' //IF `env` is PRODUCTION
- ? path.join(__dirname, 'config', env, 'special.json') //load a special file
+ cc(
+ //OVERRIDE SETTINGS WITH COMMAND LINE OPTS
+ opts,
+
+ //FILE NAMED BY ENV
+ path.join(__dirname, 'config.' + env + '.json'),
+
+ //IF `env` is PRODUCTION
+ env === 'prod'
+ ? path.join(__dirname, 'special.json') //load a special file
: null //NULL IS IGNORED!
- path.join(__dirname, 'config', env, 'config.json'), //SUBDIR FOR ENV CONFIG
- { // DEFAULTS IS LAST
+
+ //SUBDIR FOR ENV CONFIG
+ path.join(__dirname, 'config', env, 'config.json'),
+
+ //SEARCH PARENT DIRECTORIES FROM CURRENT DIR FOR FILE
+ cc.find('config.json'),
+
+ //PUT DEFAULTS LAST
+ {
host: 'localhost'
port: 8000
})
@@ -36,3 +54,8 @@ FINALLY, EASY FLEXIBLE CONFIGURATIONS!
##see also: (proto-list)[https://github.com/isaacs/proto-list/]
+##TODO
+
+ * add support for more types of parser,
+ yaml, ini, whatever I can find in npm.
+ * if string is http://... load config from internet. (useful for devops)
View
13 test/find-file.js
@@ -0,0 +1,13 @@
+
+var fs = require('fs')
+ , assert = require('assert')
+ , objx = {
+ rand: Math.random()
+ }
+
+fs.writeFileSync('/tmp/random-test-config.json', JSON.stringify(objx))
+
+var cc = require('../')
+var path = cc.find('tmp/random-test-config.json')
+
+assert.equal(path, '/tmp/random-test-config.json')

0 comments on commit a586bec

Please sign in to comment.