-
Notifications
You must be signed in to change notification settings - Fork 0
/
configLoader.ts
39 lines (34 loc) · 1.06 KB
/
configLoader.ts
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
import { existsSync, readFileSync } from "fs";
import { join } from "path";
import { ConfigurationOptions } from "./lib/options";
const CONFIG_FILE_NAME = "minomax.config.json";
const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME);
const projectHasConfig = existsSync(projectConfigFile);
let projectConfig: ConfigurationOptions = {} as ConfigurationOptions;
let defaultConfig: ConfigurationOptions = {} as ConfigurationOptions;
if (projectHasConfig) {
//load project config
try {
projectConfig = JSON.parse(
readFileSync(projectConfigFile, { encoding: "utf8" }),
);
} catch (err) {
if (err instanceof SyntaxError) {
console.log(
"Error: Check configuration file if there any syntax mistake",
);
} else {
console.log("Unexpected Error while loading settings");
}
process.exit(1);
}
}
//load default configuration
defaultConfig = JSON.parse(
readFileSync(join(__dirname, CONFIG_FILE_NAME), { encoding: "utf8" }),
);
const configurations: ConfigurationOptions = {
...defaultConfig,
...projectConfig,
};
export default configurations;