/
config.js
52 lines (42 loc) · 1.24 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
config.js
=========
This object returns all config info for the app. It handles reading the `testem.yml` config file.
*/
var fs = require('fs')
, yaml = require('js-yaml')
function Config(progOptions){
this.progOptions = progOptions
this.config = null
}
Config.prototype.read = function(callback){
var configFile = this.progOptions.file
, self = this
, 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)
})
}
Config.prototype.get = function(key){
if (key in this.progOptions)
return this.progOptions[key]
else if (this.config && key in this.config)
return this.config[key]
else
return null
}
Config.prototype.isCwdMode = function(){
return !this.get('src_files') && !this.get('test_page')
}
module.exports = Config