@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { join } from "path" ;
import { existsSync, readFileSync , copy FileSync } from "fs" ;
import { copyFileSync, existsSync , mkdirSync , read FileSync } 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
}