-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-loader.js
executable file
·52 lines (43 loc) · 1.47 KB
/
config-loader.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
var parseArgs = function (key, cmdArgs) {
var data = {};
try {
var cmdArgs = process.argv.slice(2);
if (cmdArgs && cmdArgs.length > 0) {
for (let index = 0; index < cmdArgs.length; index++) {
const item = cmdArgs[index];
if (item === '-w' || item === '-d' || item === '-p' || item === '-t' || item === '-c') {
data[item] = cmdArgs[index + 1];
console.error("Found arg " + item + " with value " + data[item]);
}
}
}
} catch (error) {
console.error("Error parsing arguments: ", error);
}
return data;
}
var cmdArgs = parseArgs();
var configFile = './config.json';
var configPath = "./";
if (cmdArgs['-c']) {
configPath = cmdArgs['-c'] + "/";
console.log("Found external config.json", configPath);
configFile = configPath + 'config.json'
}
var config;
try {
config = require(configFile)
} catch (error) {
console.log("Fallback to default config.json");
configFile = './config.json';
config = require(configFile)
}
console.log("Config:", config);
config.configPath = configPath;
config.webPath = cmdArgs['-w'] ? cmdArgs['-w'] : config.webPath;
config.rootDir = cmdArgs['-d'] ? cmdArgs['-d'] : config.rootDir;
config.port = cmdArgs['-p'] ? cmdArgs['-p'] : config.port;
config.token = cmdArgs['-t'] ? cmdArgs['-t'] : config.token;
//default values
config.ext = config.ext || ["mp3", "ogg"];
module.exports = config;