This repository was archived by the owner on Oct 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.js
66 lines (49 loc) · 1.65 KB
/
install.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
const fse = require('fs-extra');
const helper = require('./helper');
const nestedAssign = require('nested-object-assign');
const deepForEach = require('deep-for-each');
const objectPath = require('object-path');
const stringify = require('json-stable-stringify');
const { default_config } = helper;
let custom_config = {};
const default_credentials = {
twitch: {
clientID: "",
clientSecret: ""
},
discord: {
clientID: "",
token: ""
}
}
let custom_credentials = {};
function compare(a, b){
return a.key == "commands" ? 1 : a.key > b.key;
}
if(fse.existsSync('./config.json')){
try{
custom_config = JSON.parse(fse.readFileSync('./config.json'), 'utf8');
}catch(e){
module.exports.error('malformatted config.json, exiting...');
process.exit(1);
}
}
let output_config = {};
nestedAssign(output_config, custom_config, default_config);
deepForEach(output_config, (value, key, subject, path) => {
if(Array.isArray(value))
objectPath.set(output_config, path, [...new Set(value)]);
});
fse.writeFileSync('./config.json', stringify(output_config, { cmp: compare, space: 2 }));
if(fse.existsSync('./credentials.json')){
try{
custom_credentials = JSON.parse(fse.readFileSync('./credentials.json'), 'utf8');
}catch(e){
module.exports.error('malformatted credentials.json, exiting...');
process.exit(1);
}
}
let output_credentials = {};
nestedAssign(output_credentials, custom_credentials, default_credentials);
fse.writeFileSync('./credentials.json', stringify(output_credentials, { space: 2 }));
console.log('Configuration files successfully generated');