Run pre-commit hooks over existing codebase

Co-Authored-By: Ben Phelps <ben@phelps.io>
This commit is contained in:
shamoon
2023-10-17 23:26:55 -07:00
parent fa50bbad9c
commit 19c25713c4
387 changed files with 4785 additions and 4109 deletions

View File

@@ -9,22 +9,24 @@ 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 const CONF_DIR = process.env.HOMEPAGE_CONFIG_DIR
? process.env.HOMEPAGE_CONFIG_DIR
: join(process.cwd(), "config");
export default function checkAndCopyConfig(config) {
if (!existsSync(CONF_DIR)) {
mkdirSync(CONF_DIR, { recursive: true });
mkdirSync(CONF_DIR, { recursive: true });
}
const configYaml = join(CONF_DIR, config);
if (!existsSync(configYaml)) {
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
try {
copyFileSync(configSkeleton, configYaml)
copyFileSync(configSkeleton, configYaml);
console.info("%s was copied to the config folder", config);
} catch (err) {
console.error("error copying config", err);
throw err;
console.error("error copying config", err);
throw err;
}
return true;
@@ -42,7 +44,9 @@ function getCachedEnvironmentVars() {
let cachedVars = cache.get(cacheKey);
if (!cachedVars) {
// initialize cache
cachedVars = Object.entries(process.env).filter(([key, ]) => key.includes(homepageVarPrefix) || key.includes(homepageFilePrefix));
cachedVars = Object.entries(process.env).filter(
([key]) => key.includes(homepageVarPrefix) || key.includes(homepageFilePrefix),
);
cache.put(cacheKey, cachedVars);
}
return cachedVars;
@@ -50,7 +54,8 @@ function getCachedEnvironmentVars() {
export function substituteEnvironmentVars(str) {
let result = str;
if (result.includes('{{')) { // crude check if we have vars to replace
if (result.includes("{{")) {
// crude check if we have vars to replace
const cachedVars = getCachedEnvironmentVars();
cachedVars.forEach(([key, value]) => {
if (key.startsWith(homepageVarPrefix)) {
@@ -77,13 +82,13 @@ export function getSettings() {
// support yaml list but old spec was object so convert to that
// see https://github.com/gethomepage/homepage/issues/1546
if (Array.isArray(initialSettings.layout)) {
const layoutItems = initialSettings.layout
initialSettings.layout = {}
layoutItems.forEach(i => {
const name = Object.keys(i)[0]
initialSettings.layout[name] = i[name]
})
const layoutItems = initialSettings.layout;
initialSettings.layout = {};
layoutItems.forEach((i) => {
const name = Object.keys(i)[0];
initialSettings.layout[name] = i[name];
});
}
}
return initialSettings
return initialSettings;
}