-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*global module:false,require:false*/ | ||
var debug = require('debug')('config'), | ||
path = require('path'), | ||
etcjs = (function() { | ||
|
||
var _getEnvironmentVariable = function(env) { | ||
'use strict'; | ||
var regEx = /^[a-zA-Z0-9_]*$/; | ||
|
||
if (!env) { | ||
debug('missing node environment variable'); | ||
throw new Error('missing node environment'); | ||
} | ||
|
||
if (!regEx.test(env)) { | ||
debug('invalid node environment variable'); | ||
throw new Error('invalid node environment'); | ||
} | ||
return env; | ||
}; | ||
|
||
return { | ||
load: function(options, callback) { | ||
'use strict'; | ||
var globalEnv, | ||
localEnv, | ||
env = _getEnvironmentVariable(process.env.NODE_ENV), | ||
globalPath, | ||
localPath; | ||
if (!options || !options.dir || !options.defaultFile) { | ||
throw new Error('Missing required option `file`'); | ||
} | ||
globalPath = path.normalize(options.defaultFile); | ||
localPath = path.normalize(options.dir + '/' + env); | ||
debug('initializing configuration for %s', env); | ||
// NOTE: by loading the global env first we ensure that env. var. can be | ||
// overwritten by the local configuration. | ||
globalEnv = require(globalPath); | ||
env = localEnv = require(localPath); | ||
// NOTE: inform that loading the configuration is completed. | ||
if (callback && typeof callback === 'function') { | ||
callback(); | ||
} | ||
} | ||
}; | ||
})(); | ||
|
||
module.exports = etcjs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
{ | ||
"name": "etcjs", | ||
"version": "0.11.0", | ||
"private": false, | ||
"description": "Simple stupid node.js configuration module", | ||
"main": "lib/config", | ||
"scripts": { | ||
"start": "node bin/init", | ||
"test": "mocha", | ||
"test-watch": "mocha --opts ./test/mocha-watch.opts", | ||
"cover": "istanbul cover node_modules/mocha/bin/_mocha", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly", | ||
"lint": "jshint ." | ||
}, | ||
"engines": { | ||
"node": ">=0.8.x" | ||
}, | ||
"author": "Mohamed Boughaba <[email protected]>", | ||
"contributors": [ | ||
{ | ||
"name": "Mohamed Boughaba", | ||
"email": "[email protected]" | ||
"name": "etcjs", | ||
"version": "0.11.0", | ||
"private": false, | ||
"description": "Simple stupid node.js configuration module", | ||
"main": "lib/etcjs", | ||
"scripts": { | ||
"start": "node bin/init", | ||
"test": "mocha", | ||
"test-watch": "mocha --opts ./test/mocha-watch.opts", | ||
"cover": "istanbul cover node_modules/mocha/bin/_mocha", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly", | ||
"lint": "jshint ." | ||
}, | ||
"engines": { | ||
"node": ">=0.8.x" | ||
}, | ||
"author": "Mohamed Boughaba <[email protected]>", | ||
"contributors": [{ | ||
"name": "Mohamed Boughaba", | ||
"email": "[email protected]" | ||
}], | ||
"license": "MIT", | ||
"dependencies": { | ||
"debug": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"growl": "^1.8.1", | ||
"istanbul": "^0.3.14", | ||
"mocha": "^2.2.5", | ||
"precommit-hook": "latest", | ||
"should": "^6.0.3" | ||
}, | ||
"keywords": [ | ||
"etc", | ||
"js", | ||
"configuration", | ||
"node", | ||
"simple" | ||
], | ||
"pre-commit": [ | ||
"lint", | ||
"test" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mboughaba/etcjs.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mboughaba/etcjs/issues" | ||
} | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"debug": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"growl": "^1.8.1", | ||
"istanbul": "^0.3.14", | ||
"mocha": "^2.2.5", | ||
"precommit-hook": "latest", | ||
"should": "^6.0.3" | ||
}, | ||
"keywords": [ | ||
"etc", | ||
"js", | ||
"configuration", | ||
"node", | ||
"simple" | ||
], | ||
"pre-commit": [ | ||
"lint", | ||
"test" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mboughaba/etcjs.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mboughaba/etcjs/issues" | ||
} | ||
} |
Oops, something went wrong.