-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.js
71 lines (62 loc) · 1.89 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import fs from "node:fs/promises";
import Log from "../src/util/log.js";
// ========================= //
// = Copyright (c) NullDev = //
// ========================= //
/**
* @param {any} item
* @returns {boolean}
*/
const isObject = item => item && typeof item === "object" && !Array.isArray(item);
/**
* Deep Merge of two objects
*
* @template {object} T
* @template {object} T2
* @param {T} target
* @param {T2 & Partial<T>} source
* @returns {T & T2}
*/
const deepMerge = function(target, source){
if (isObject(target) && isObject(source)){
for (const key in source){
if (isObject(source[key])){
if (!target[key]) target[key] = {};
deepMerge(target[key], source[key]);
}
else target[key] = source[key];
}
}
return /** @type {T & T2} */ (target);
};
try {
await fs.access("./config/config.custom.js");
}
// eslint-disable-next-line no-unused-vars
catch (error){
Log.error("Config file not found. To create one, either copy 'config.template.js' and rename it to 'config.custom.js' or run 'npm run generate-config'.");
process.exit(1);
}
try {
await fs.access("./config/config.template.js");
}
// eslint-disable-next-line no-unused-vars
catch (error){
Log.error("Config template file not found. This is needed to read default values. Please re-clone the repository.");
process.exit(1);
}
// @ts-ignore
const configCustom = (await import("./config.custom.js")).default;
const configBase = (await import("./config.template.js")).default;
const packageJSON = JSON.parse(await fs.readFile("./package.json", "utf-8"));
export const meta = {
getVersion: () => packageJSON.version,
getName: () => packageJSON.name,
getAuthor: () => packageJSON.author,
};
export const config = {
...deepMerge(
configBase,
/** @type {Partial<typeof configBase>} */ (configCustom),
),
};