-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
31 lines (25 loc) · 863 Bytes
/
config.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
import { readFileSync } from "fs";
import { safeJsonParse } from "./utils.js";
import isEmpty from "lodash.isempty";
import isEqual from "lodash.isequal";
const schema = Object.freeze({
token: typeof String,
channels: typeof Array,
members: typeof Array
});
const load = (configPath) => {
const configFileContent = readFileSync(configPath, "utf-8");
const configJson = safeJsonParse(configFileContent);
if (isEmpty(configJson)) {
throw `config.json is malformed: ${configFileContent}`;
}
Object.entries(schema).forEach((property, type) => {
if (!configJson.hasOwnProperty(property) && isEqual(typeof configJson[property], type)) {
throw `[config.json] Missing or malformed property: ${property}`
}
})
return configJson;
}
export default {
load
}