2022-12-01 12:03:37 +01:00
|
|
|
import path from "path";
|
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
import deepmerge from "deepmerge";
|
2022-12-30 12:12:04 +01:00
|
|
|
import { ConfigShape } from "TokensGenerator";
|
|
|
|
|
import { workPath } from "Paths";
|
2023-01-02 12:06:00 +01:00
|
|
|
import { register } from "ts-node";
|
2022-12-01 12:03:37 +01:00
|
|
|
import Config from "./Config";
|
|
|
|
|
|
|
|
|
|
const getLocalConfig = async () => {
|
|
|
|
|
const filename = Config.configurationFilenames
|
|
|
|
|
.map((filename_) => path.join(workPath(), filename_))
|
|
|
|
|
.find((filename_) => fs.existsSync(filename_));
|
|
|
|
|
|
|
|
|
|
if (!filename) {
|
|
|
|
|
console.log("No local config found, using default config.");
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2023-01-02 12:06:00 +01:00
|
|
|
console.log("Found local config file: " + filename);
|
|
|
|
|
|
|
|
|
|
const ext = path.extname(filename);
|
|
|
|
|
if (ext === ".ts") {
|
|
|
|
|
registerTypescriptLoader();
|
|
|
|
|
}
|
2022-12-01 12:03:37 +01:00
|
|
|
|
|
|
|
|
const config = await import(filename);
|
|
|
|
|
return config.default;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-02 12:06:00 +01:00
|
|
|
const registerTypescriptLoader = () => {
|
|
|
|
|
register({
|
|
|
|
|
moduleTypes: {
|
|
|
|
|
"**/*.ts": "cjs",
|
|
|
|
|
},
|
|
|
|
|
compilerOptions: {
|
|
|
|
|
module: "commonjs",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-01 12:03:37 +01:00
|
|
|
const getDistConfig = async () => {
|
|
|
|
|
const config = await import("./cunningham.dist.js");
|
|
|
|
|
return config.default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getConfig = async () => {
|
|
|
|
|
const localConfig = await getLocalConfig();
|
|
|
|
|
const distConfig = await getDistConfig();
|
|
|
|
|
const config: ConfigShape = deepmerge(distConfig, localConfig);
|
|
|
|
|
return config;
|
|
|
|
|
};
|