You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
978 B
37 lines
978 B
2 years ago
|
/* eslint-disable no-console */
|
||
2 years ago
|
import { join } from "path";
|
||
2 years ago
|
import { existsSync, copyFile, readFileSync } from "fs";
|
||
2 years ago
|
|
||
2 years ago
|
import yaml from "js-yaml";
|
||
2 years ago
|
|
||
|
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) => {
|
||
2 years ago
|
if (err) {
|
||
2 years ago
|
console.error("error copying config", err);
|
||
2 years ago
|
throw err;
|
||
|
}
|
||
2 years ago
|
console.info("%s was copied to the config folder", config);
|
||
|
});
|
||
2 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
yaml.load(readFileSync(configYaml, "utf8"));
|
||
|
return true;
|
||
|
} catch (e) {
|
||
|
return { ...e, config };
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
export function getSettings() {
|
||
2 years ago
|
checkAndCopyConfig("settings.yaml");
|
||
|
|
||
2 years ago
|
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
||
2 years ago
|
const fileContents = readFileSync(settingsYaml, "utf8");
|
||
2 years ago
|
return yaml.load(fileContents);
|
||
|
}
|