Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.0.1 release

  • Loading branch information...
commit 9cf387a6f0de7a458b14349fafa4602b9cf1d9c4 0 parents
@yarcowang yarcowang authored
59 README.md
@@ -0,0 +1,59 @@
+iConfig
+========
+
+`iCnf` is a nodejs module for supporting configeration.
+
+
+**License: This project is under GPL/BSD**
+
+Intro
+-----
+There already exists a module named `config`, but for me, it is too large: i dont want supporting yml etc features, i just a simple solution.
+
+So that's why i create this module. Certainly choice is in your mind.
+
+How to install
+--------------
+`npm install icnf`
+
+How to use
+-----------
+* create several config files under some directory in your project, for example:
+
+```
+<YOUR PROJECT>
++ etc/
+ + production.json
+ + testing.json
+ + development.json
+```
+
+according to your needs. The format should always be **json format**.
+
+* use icnf in your code
+
+```
+var icnf = require('icnf')(__dirname); // app root directory, that is <YOUR PROJECT>
+
+var config = icnf(); // default is process.env.NODE_ENV || 'production', so it will auto use etc/production.json.
+
+var config = icnf('development'); // then, now it will choose etc/development.json
+```
+
+Extra notice
+------------
+* the config file is `<PROJECT>/etc/<ENV>.json`
+
+ChangeLog
+----------
+
+Sugguestion
+-----------
+You could contact [me][] through <yarco.wang@gmail.com> for this extension.
+Or for programming related things, whatever.
+
+This guy currently works in Wiredcraft.com. So you could also get him by <yarco@wiredcraft.com>
+
+All rights reserved.
+
+[me]:http://bbish.net
2  index.js
@@ -0,0 +1,2 @@
+// index
+module.exports = require('./lib/icnf');
21 lib/icnf.js
@@ -0,0 +1,21 @@
+/**
+ * @file icnf.js
+ * core file
+ *
+ * @author Yarco <yarco.wang@gmail.com>
+ * @since 2013/01/16
+ * @copyright BSD
+ */
+// vim: set tabstop=2 shiftwidth=2 softtabstop=2 noexpandtab ai si:
+
+var path = require('path');
+
+module.exports = function(dir) { // project root
+ var root = dir;
+
+ return function(env) {
+ env = env || process.env.NODE_ENV || 'production';
+ return require(path.join(root, 'etc', env + '.json')); // <PROJECT>/etc/<ENV>.json
+ }
+}
+
29 package.json
@@ -0,0 +1,29 @@
+{
+ "name": "icnf",
+ "version": "0.0.1",
+ "description": "a nodejs module for supporting configeration",
+ "main": "index.js",
+ "scripts": {
+ "test": "mocha"
+ },
+ "dependencies": {
+ },
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/yarcowang/icnf"
+ },
+ "keywords": [
+ "simple",
+ "config",
+ "json"
+ ],
+ "author": {
+ "name": "Yarco",
+ "email": "yarco.wang@gmail.com"
+ },
+ "license": "BSD"
+}
5 test/etc/development.json
@@ -0,0 +1,5 @@
+{
+ "name":"yarco",
+ "sex":"male",
+ "gf":"shunza"
+}
4 test/etc/production.json
@@ -0,0 +1,4 @@
+{
+ "name": "yarco",
+ "sex": "male"
+}
2  test/mocha.opts
@@ -0,0 +1,2 @@
+-r should
+-R spec
14 test/test.js
@@ -0,0 +1,14 @@
+var icnf = require('../')(__dirname);
+
+describe('default should using production.json', function() {
+ it('should equal to yarco', function() {
+ icnf().name.should.equal('yarco');
+ });
+});
+
+describe('development env should using development.json', function() {
+ it('should equal to shunza', function() {
+ icnf('development').gf.should.equal('shunza');
+ });
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.