-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshared.js
49 lines (43 loc) · 1.1 KB
/
shared.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
import FS from 'fs';
import Yargs from 'yargs';
/**
* Is the debug environment variable set? Used to set up some useful development things
* @type {boolean}
*/
export let Debug = process.env.UGR_ENV == 'debug';
/**
* The current working directory
* @type {string}
*/
export let CWD = process.cwd();
export let Config = {};
let ConfigPath = '';
export let argv = {};
/** The command-line arguments as read in with Yargs */
export let ParseArgs = () => Yargs
.option('config', {
alias: 'c',
describe: 'The config file to load',
type: 'string'
})
.option('port', {
alias: 'p',
describe: 'Port to listen on',
type: 'number'
})
.default({
port: 3000,
config: 'config.json'
})
.usage(`Forge Graphics Server \nUsage: $0 [-c config] [-p port]`)
.help().alias('h', 'help')
.argv;
export function LoadConfig(path) {
if (!path) Config = JSON.parse(FS.readFileSync(argv.config));
else {
ConfigPath = path;
Config = JSON.parse(FS.readFileSync(ConfigPath));
}
}
argv = ParseArgs();
LoadConfig();