-
Notifications
You must be signed in to change notification settings - Fork 77
/
generate-example-config.js
49 lines (41 loc) · 1.35 KB
/
generate-example-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
const fs = require("fs");
// Function to clear values from the object.
function ClearValues(obj) {
if (typeof obj === "object" && obj !== null) {
if (Array.isArray(obj)) {
return obj.map((item) => ClearValues(item));
} else {
let clearedObj = {};
for (let key in obj) {
clearedObj[key] = ClearValues(obj[key]);
}
return clearedObj;
}
} else {
return "";
}
}
// Read the original config.json file
fs.readFile("config.json", "utf8", (Error, Data) => {
if (Error) {
console.error("Error reading config.json:", Error);
return;
}
let ConfigData; //This stores the new configuration data.
try {
ConfigData = JSON.parse(Data);
} catch (Error) {
console.error("Error parsing JSON:", Error);
return;
}
// Clear the values from the config.json file.
const ClearedConfigData = ClearValues(ConfigData);
// Write the cleared config data to example.config.json.
fs.writeFile("example-config.json", JSON.stringify(ClearedConfigData, null, 4), (Error) => {
if (Error) {
console.error("Error writing example.config.json:", Error);
return;
}
console.log("[AUTOMATED] example-config.json has been created with cleared values.");
});
});