-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.js
54 lines (43 loc) · 1.17 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
var fs = require('fs');
module.exports = function () {
this.configFilename = '.itsconf';
this.config = {};
this.getHomeDir = function () {
return process.env.HOME
|| process.env.HOMEPATH
|| process.env.USERPROFILE;
}
this.exists = function () {
return fs.existsSync(
this.getHomeDir() + '/' + this.configFilename
);
}
this.getWriteableConfig = function () {
return JSON.stringify(this.config, null, 4);
}
this.getField = function (field) {
return this.config[field];
}
this.set = function (config) {
this.config = config;
}
this.load = function () {
try {
var loadedConfig = JSON.parse(fs.readFileSync(
this.getHomeDir() + '/' + this.configFilename
));
this.set(loadedConfig);
} catch (err) {
throw err;
}
}
this.save = function () {
fs.writeFile(
this.getHomeDir() + '/' + this.configFilename,
this.getWriteableConfig(),
function (err) {
if (err)
throw err;
});
}
}