|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
import { join } from "path";
|
|
|
|
|
import { existsSync, readFileSync, copyFileSync } from "fs";
|
|
|
|
|
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
|
|
|
|
|
|
|
|
import cache from "memory-cache";
|
|
|
|
|
import yaml from "js-yaml";
|
|
|
|
@ -9,8 +9,14 @@ const cacheKey = "homepageEnvironmentVariables";
|
|
|
|
|
const homepageVarPrefix = "HOMEPAGE_VAR_";
|
|
|
|
|
const homepageFilePrefix = "HOMEPAGE_FILE_";
|
|
|
|
|
|
|
|
|
|
export const CONF_DIR = process.env.HOMEPAGE_CONFIG_DIR ? process.env.HOMEPAGE_CONFIG_DIR : join(process.cwd(), "config");
|
|
|
|
|
|
|
|
|
|
export default function checkAndCopyConfig(config) {
|
|
|
|
|
const configYaml = join(process.cwd(), "config", config);
|
|
|
|
|
if (!existsSync(CONF_DIR)) {
|
|
|
|
|
mkdirSync(CONF_DIR, { recursive: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const configYaml = join(CONF_DIR, config);
|
|
|
|
|
if (!existsSync(configYaml)) {
|
|
|
|
|
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
|
|
|
|
|
try {
|
|
|
|
@ -62,7 +68,7 @@ export function substituteEnvironmentVars(str) {
|
|
|
|
|
export function getSettings() {
|
|
|
|
|
checkAndCopyConfig("settings.yaml");
|
|
|
|
|
|
|
|
|
|
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
|
|
|
|
const settingsYaml = join(CONF_DIR, "settings.yaml");
|
|
|
|
|
const rawFileContents = readFileSync(settingsYaml, "utf8");
|
|
|
|
|
const fileContents = substituteEnvironmentVars(rawFileContents);
|
|
|
|
|
const initialSettings = yaml.load(fileContents) ?? {};
|
|
|
|
@ -79,6 +85,5 @@ export function getSettings() {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return initialSettings
|
|
|
|
|
}
|
|
|
|
|