-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathconfig.js
54 lines (48 loc) · 1.33 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
const fs = require("fs");
function cloneObject(object) {
return JSON.parse(JSON.stringify(object));
}
const storageFilename = "storage.json"
var default_config;
if (fs.existsSync(__dirname + "/dcs_config.js")) {
default_config = require("./dcs_config");
} else {
default_config = require("./dcs_config.json");
}
default_config = cloneObject(default_config);
var config = default_config;
var storage = {};
if (fs.existsSync(__dirname + "/" + storageFilename)) {
storage = require("./" + storageFilename);
if (storage) {
config = Object.assign(config, storage);
}
}
//if(fs.existsSync(__dirname+"/dcs_config.js")){
// fs.writeFileSync(__dirname+"/dcs_config.json", JSON.stringify(config,null,2));
//}
module.exports = {
get: function(key) {
return config[key];
},
getAll: function() {
return config;
},
set: function(key, value) {
config[key] = value;
if (value === null) {
delete(config[key]);
}
},
setAll: function(options) {
config = Object.assign(config, options);
},
save: function(key, value) {
this.set(key, value);
storage[key] = value;
if (value === null) {
delete(storage[key]);
}
fs.writeFileSync(__dirname + "/" + storageFilename, JSON.stringify(storage));
}
};