-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig.js
66 lines (48 loc) · 1.48 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var yaml = require('js-yaml')
, fs = require('fs')
, path = require('path');
var Config = function (peak, options) {
this.peak = peak;
this.file_path = path.join(this.peak.path, '.peakconfig.yml');
this.config = {};
this.options_argument = options || {};
this.load_defaults();
this.load_file();
}
Config.prototype = {
load_defaults: function () {
this.config.output_path = '.peak';
this.config.port = 1111;
this.config.index = 'index.jade';
},
load_file: function () {
var file;
if (fs.existsSync(this.file_path)) {
file = yaml.safeLoad(fs.readFileSync(this.file_path, 'utf8'));
for (var opt in file) this.config[opt] = file[opt];
}
},
options: function (action) {
var options = {};
for (option in this.config) {
options[option] = this.config[option];
}
if (typeof options[action] === 'object') {
for (option in options[action]) options[option] = options[action][option];
}
for (option in this.options_argument) {
if (this.options_argument[option] &&
typeof this.options_argument[option] !== 'function') options[option] = this.options_argument[option];
}
if (action) {
if (!options.ignore_paths || !options.ignore_paths instanceof Array) {
options.ignore_paths = [];
}
if (options.ignore_paths.indexOf(options.output_path) == -1) {
options.ignore_paths.push(options.output_path);
}
}
return options;
}
}
module.exports = Config;