Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
v0.0.2 with support for default configs
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Mar 12, 2013
1 parent 900191c commit 2a5956c
Show file tree
Hide file tree
Showing 29 changed files with 8,096 additions and 6,942 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
node_modules
*.iml
.idea
5 changes: 5 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/scopes/scope_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions .jshintrc
@@ -0,0 +1,74 @@
{
"predef": [
"jasmine",
"spyOn",
"it",
"console",
"describe",
"expect",
"beforeEach",
"afterEach",
"waits",
"waitsFor",
"runs",
"$",
"jQuery",
"_",
"require",
"define",
"sinon",
"thumbs"
],

"node" : true,
"browser" : true,
"devel" : true,
"jquery" : true,

"bitwise" : false,
"camelcase" : true,
"curly" : true,
"eqeqeq" : true,
"forin" : false,
"immed" : true,
"indent" : 4,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"noempty" : true,
"nonew" : false,
"plusplus" : false,
"quotmark" : false,
"regexp" : false,
"undef" : true,
"unused" : false,
"strict" : false,
"trailing" : true,
"white" : false,

"asi" : false,
"boss" : false,
"debug" : false,
"eqnull" : true,
"es5" : true,
"esnext" : true,
"evil" : false,
"expr" : true,
"funcscope" : false,
"globalstrict" : false,
"iterator" : false,
"lastsemic" : false,
"laxbreak" : false,
"laxcomma" : false,
"loopfunc" : false,
"multistr" : false,
"onecase" : false,
"proto" : false,
"regexdash" : false,
"scripturl" : false,
"smarttabs" : false,
"shadow" : false,
"sub" : true,
"supernew" : true,
"validthis" : false
}
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.6
- 0.8
47 changes: 47 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,47 @@
/*global module:false*/
module.exports = function (grunt) {
var fs = require('fs');

// grunt doesn't natively support reading config from .jshintrc yet
var jshintOptions = JSON.parse(fs.readFileSync('./.jshintrc'));

// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' +
' Licensed <%= pkg.license %> */'
},

jshint: {
file: "./lib/*.js",
options: {
jshintrc: '.jshintrc'
}
},

it: {
all: {
src: 'test/**/*.test.js',
options: {
timeout: 3000, // not fully supported yet
reporter: 'dotmatrix'
}
}
},
watch: {
files: '<config:lint.files>',
tasks: 'lint it'
},
uglify: {}
});

grunt.loadNpmTasks('grunt-it');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task.
grunt.registerTask('default', ['jshint', 'it']);

};
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2012-2013 doug@c2fo.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.
85 changes: 75 additions & 10 deletions README.md
@@ -1,12 +1,14 @@
#gofigure
[![Build Status](https://travis-ci.org/C2FO/gofigure.png)](https://travis-ci.org/C2FO/gofigure)

# gofigure

Gofigure is a configuration tool for node to help in the gathering and monitoring of configuration files in node.

# Installation

npm install gofigure

#Usage
# Usage


* [Loading A Configuration](#load)
Expand All @@ -20,7 +22,7 @@ Gofigure is a configuration tool for node to help in the gathering and monitorin
* [Environments](#environments)

<a name="load"></a>
##Loading configurations
## Loading configurations

Gofigure currently handles the loading of JSON files for configurations.

Expand All @@ -31,6 +33,7 @@ To Get an instance of a configuration object use the `gofigure` method. The `gof
* [monitor](#monitoring) : set to true to monitor changes to configuration files.
* `ignoreMissing` : By default `gofigure` will ignore missing directories. Set this to false to precent the ignoring of missing configuration directories.
* [environment](#environments) : By default will look for `process.env.NODE_ENV` if this is not set then gofigure will read all properties. If you wish to explicity set the environment then set this property.
* `defaultEnvironment` [`*`]: The key that represents default values to be set when an environment is used.

```javascript

Expand Down Expand Up @@ -68,7 +71,7 @@ var config = loader.loadSync();
```

<a name="loadDir"></a>
###Directories of configurations
### Directories of configurations
To load directories that contain configuration files in the options object provide locations property that is an array of directories than contain your configurations.

```javascript
Expand Down Expand Up @@ -107,7 +110,7 @@ loader.load(function(err, config){
```

<a name="loadFiles"></a>
###Files
### Files

You may also load specific files rather than entire directories.

Expand All @@ -123,12 +126,12 @@ loader.load(function(err, config){
Again order matters `/prod/configs/config1.json` will override `__dirname + "/config.json"`

<a name="monitoring"></a>
##Monitoring
## Monitoring

Gofigure supports the monitoring of changes to configuration files.

<a name="monitoringAll"></a>
###All files
### All files

To enable monitoring you can specify monitor to true in the options.

Expand All @@ -143,7 +146,7 @@ loading.on("my.cool.property", function(newValue){
});
```
<a name="monitoringSome"></a>
###Individual Files
### Individual Files

To monitor certain files you can use the files property and with object that have a `monitor : true` KV pair.

Expand All @@ -167,7 +170,7 @@ loading.on("my.cool.property", function(newValue){
Just `config1.json` will be monitored for changes.

<a name="monitoringSyntax"></a>
###Property topic syntax
### Property topic syntax

To listen to all properties

Expand Down Expand Up @@ -236,7 +239,7 @@ loading.on("my.{cool|notCool}.{property|otherProperty}", function(propName, newV
```

<a name="monitoringCB"></a>
###Callback Arguments
### Callback Arguments


The property change callback will pass in the following values depending on the arity of the callback.
Expand Down Expand Up @@ -383,6 +386,68 @@ var loader = gofigure({

```

You may also share properties across enviroments by using `*` or overriding `defaultEnvironment` when initializing.

```json

{
"*": {
"logging":{
"patio":{
"level":"ERROR",
"appenders":[
{
"type":"RollingFileAppender",
"file":"/var/log/myApp/patio.log"
}
]
}
},
"app" : {
"host" : "localhost",
"port" : "8088"
},
"MYSQL_DB" : "mysql://test:testpass@localhost:3306/db",
"MONGO_DB" : "mongodb://test:testpass@localhost:27017/db"
},
"development": {
"logging":{
"patio":{
"appenders":[{
"type":"ConsoleAppender"
}]
}
},
"MYSQL_DB" : "mysql://test:testpass@localhost:3306/dev_db",
"MONGO_DB" : "mongodb://test:testpass@localhost:27017/dev_db"
},
"production": {
"app" : {
"host" : "prod.mydomain.com",
"port" : "80"
},
"MYSQL_DB" : "mysql://test:testpass@prod.mydomain.com:3306/prod_db",
"MONGO_DB" : "mongodb://test:testpass@prod.mydomain.com:27017/prd_db"
},
"test": {
"logging":{
"patio":{
"level":"INFO"
}
},
"app" : {
"host" : "test.mydomain.com",
"port" : "80"
},
"MYSQL_DB" : "mysql://test:testpass@test.mydomain.com:3306/test_db",
"MONGO_DB" : "mongodb://test:testpass@test.mydomain.com:27017/test_db"
}
}

```

Now each environment only has to override properties specific to that env.

License
-------

Expand Down

0 comments on commit 2a5956c

Please sign in to comment.