-
Notifications
You must be signed in to change notification settings - Fork 0
/
yargs.js
87 lines (68 loc) · 1.85 KB
/
yargs.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* INI EXAMPLE
*
* [CONFIG]
PORT=3333
DIRTY=true
*/
const { constants } = require('./constants');
const { config } = require('./config');
const { Utils } = require("./utils/utils");
const fs = require('fs');
const parser = require("ini-parser-encoder");
let utils = new Utils();
let userINI = {};
let userArgs = {};
let userCustoms = {
port: false,
dirty: false,
blacklist: false
};
if (fs.existsSync("./user.ini")) {
config.DEBUG && utils.console("Found user config");
config.DEBUG && utils.console(" ");
userINI = parser.parseFileSync("./user.ini");
if (userINI.CONFIG.PORT) {
userCustoms.port = true;
userArgs.PORT = userINI.CONFIG.PORT;
}
if (userINI.CONFIG.DIRTY) {
userCustoms.dirty = true;
userArgs.CLEAN_ON_STARTUP = userINI.CONFIG.DIRTY;
}
if (userINI.CONFIG.BLACKLIST) {
userCustoms.blacklist = true;
userArgs.BLACKLIST = userINI.CONFIG.BLACKLIST.split(",");
}
}
var argv = require("yargs").option(
"port", {
alias: "p",
describe: "Set a custom port to use instead of " + config.PORT
}
).option(
"dirty", {
alias: "d",
describe: "Do not wipe previous session data on startup"
}
).version(constants.APP.VERSION).help().argv;
if (argv.port && Number.isInteger(argv.port) && (argv.port >= 0) && (argv.port <=65535)) {
userCustoms.port = true;
userArgs.PORT = argv.port;
}
if (argv.dirty) {
userCustoms.dirty = true;
userArgs.CLEAN_ON_STARTUP = false;
}
if (userCustoms.port) {
config.DEBUG && utils.console(" ");
config.DEBUG && utils.console("Starting with custom port: " + userArgs.PORT);
}
if (userCustoms.dirty) {
config.DEBUG && utils.console("Not cleaning session data this run");
}
if (userCustoms.blacklist) {
config.DEBUG && utils.console("Found a black list. Will ignore requests with " + userINI.CONFIG.BLACKLIST);
}
config.DEBUG && utils.console(" ");
exports.userArgs = Object.assign({}, config, userArgs);