-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigLoader.ts
33 lines (26 loc) · 937 Bytes
/
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
import { existsSync } from "node:fs";
import { join } from "node:path";
import { configurationOptions } from "./lib/types";
export default function loadConfig(): configurationOptions {
const CONFIG_FILE_NAME = "richie.config";
const projectConfigFile = join(process.cwd(), `${CONFIG_FILE_NAME}.js`);
const projectHasConfig = existsSync(projectConfigFile);
let projectConfig: configurationOptions = {} as configurationOptions;
let defaultConfig: configurationOptions = {} as configurationOptions;
if (projectHasConfig) {
//load project config
try {
projectConfig = require(projectConfigFile).default;
} catch (err) {
console.log("Error while loading settings\n", err);
process.exit(1);
}
}
//load default configuration
defaultConfig = require(join(__dirname, CONFIG_FILE_NAME)).default;
const configurations: configurationOptions = {
...defaultConfig,
...projectConfig,
};
return configurations;
}