Skip to content

Commit

Permalink
Implement JSON config file support
Browse files Browse the repository at this point in the history
Supporting JSON is nice for people who are familiar with it. It's also nice if you want to pass in JavaScript objects as options
  • Loading branch information
Raynos authored and airportyh committed Jul 5, 2012
1 parent e6bc272 commit 05a0d13
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/custom_adapter/testem.json
@@ -0,0 +1,3 @@
{
"framework": "custom"
}
1 change: 0 additions & 1 deletion examples/custom_adapter/testem.yml

This file was deleted.

3 changes: 3 additions & 0 deletions examples/mocha_simple/testem.json
@@ -0,0 +1,3 @@
{
"framework": "mocha"
}
1 change: 0 additions & 1 deletion examples/mocha_simple/testem.yml

This file was deleted.

17 changes: 13 additions & 4 deletions lib/config.js
Expand Up @@ -18,11 +18,20 @@ function Config(progOptions){
Config.prototype.read = function(callback){
var configFile = this.progOptions.file
, self = this
fs.readFile(configFile, function(err, data){
if (!err){
var cfg = yaml.load(String(data))
self.config = cfg
, jsonConfigFile = configFile.replace(/\.yml$/, ".json")

fs.readFile(configFile, function (err, data) {
if (err) {
return fs.readFile(jsonConfigFile, function (err, data) {
if (!err) {
var cfg = JSON.parse(data.toString())
self.config = cfg
}
if (callback) callback.call(self)
})
}
var cfg = yaml.load(String(data))
self.config = cfg
if (callback) callback.call(self)
})
}
Expand Down

0 comments on commit 05a0d13

Please sign in to comment.