1 | import {homedir} from "os";
|
2 | import {readFileSync} from "fs";
|
3 |
|
4 | export let configFile = null
|
5 |
|
6 | if(homedir){
|
7 | configFile = homedir() + "/.rallyconfig";
|
8 | }
|
9 |
|
10 | let configObject;
|
11 | export function loadConfig(file){
|
12 | if(file) configFile = file;
|
13 | if(!configFile) return;
|
14 |
|
15 | configObject = {hasConfig: true};
|
16 | try{
|
17 | let json = readFileSync(configFile);
|
18 | configObject = JSON.parse(json);
|
19 | configObject.hasConfig = true;
|
20 | }catch(e){
|
21 | if(e.code == "ENOENT"){
|
22 | configObject.hasConfig = false;
|
23 |
|
24 | }else{
|
25 | throw e;
|
26 | }
|
27 | }
|
28 | }
|
29 |
|
30 | export function loadConfigFromArgs(args){
|
31 | let tempConfig = {
|
32 | hasConfig: true,
|
33 | ...args.config
|
34 | };
|
35 |
|
36 | configObject = tempConfig;
|
37 | }
|
38 |
|
39 | export function setConfig(obj){
|
40 | configObject = obj;
|
41 | }
|
42 |
|
43 | export {configObject};
|