Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 3ba8ef8ed119883f71efa7410c22612971ea8958 @rjyo committed Jun 6, 2011
Showing with 102 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +5 −0 Makefile
  5. +29 −0 Readme.md
  6. +2 −0 index.js
  7. +41 −0 lib/yaml-config.js
  8. +13 −0 package.json
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+*.sock
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,5 @@
+
+test:
+ @echo "populate me"
+
+.PHONY: test
@@ -0,0 +1,29 @@
+
+# yaml-config
+
+ Manage your configuration based on NODE_ENV, all configuration defined with yaml
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Rakuraku Jyo <jyo.rakuraku@gmail.com>
+
+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.
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/yaml-config');
@@ -0,0 +1,41 @@
+var yaml = require('yaml')
+ , fs = require('fs')
+ , Log = require('log')
+ , log = new Log(Log.DEBUG);
+
+var extend = function(dest, from) {
+ var props = Object.getOwnPropertyNames(from);
+ props.forEach(function(name) {
+ if (name in dest && typeof dest[name] == 'object') {
+ extend(dest[name], from[name]);
+ } else {
+ var destination = Object.getOwnPropertyDescriptor(from, name);
+ Object.defineProperty(dest, name, destination);
+ }
+ });
+};
+
+var readConfig = function(config_file, env) {
+ if (!env) {
+ env = process.env.NODE_ENV || 'development';
+ }
+ log.debug('Using %s environment.', env);
+
+ try {
+ var contents = fs.readFileSync(config_file);
+ var config = yaml.eval(contents.toString());
+
+ var settings = config['default'] || {};
+ var settings_env = config[env] || {};
+
+ extend(settings, settings_env);
+
+ log.debug('Settings: %s', JSON.stringify(settings));
+ return settings;
+ } catch(e) {
+ log.error(e);
+ return {};
+ }
+}
+
+module.exports.readConfig = readConfig;
@@ -0,0 +1,13 @@
+{
+ "name": "yaml-config"
+ , "version": "0.0.1"
+ , "description": "Manage your node.js app configuration based on NODE_ENV, all configuration defined in yaml"
+ , "keywords": []
+ , "author": "Rakuraku Jyo <jyo.rakuraku@gmail.com>"
+ , "dependencies": {
+ "log": ""
+ , "yaml": ""
+ }
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}

0 comments on commit 3ba8ef8

Please sign in to comment.