2022-09-06 08:39:25 +03:00
|
|
|
import { join } from "path";
|
2022-09-05 20:19:08 +03:00
|
|
|
import { existsSync, copyFile, promises as fs } from "fs";
|
2022-09-05 20:14:14 +03:00
|
|
|
import yaml from "js-yaml";
|
2022-08-24 10:44:35 +03:00
|
|
|
|
|
|
|
export default function checkAndCopyConfig(config) {
|
|
|
|
const configYaml = join(process.cwd(), "config", config);
|
|
|
|
if (!existsSync(configYaml)) {
|
|
|
|
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
|
|
|
|
copyFile(configSkeleton, configYaml, (err) => {
|
2022-08-25 13:16:03 +03:00
|
|
|
if (err) {
|
|
|
|
console.log("error copying config", err);
|
|
|
|
throw err;
|
|
|
|
}
|
2022-08-24 10:44:35 +03:00
|
|
|
console.info("%s was copied to the config folder", config);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-09-05 20:14:14 +03:00
|
|
|
|
|
|
|
export async function getSettings() {
|
|
|
|
checkAndCopyConfig("settings.yaml");
|
|
|
|
|
2022-09-06 08:39:25 +03:00
|
|
|
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
2022-09-05 20:14:14 +03:00
|
|
|
const fileContents = await fs.readFile(settingsYaml, "utf8");
|
|
|
|
return yaml.load(fileContents);
|
|
|
|
}
|