-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add repo link through config loader * config
- Loading branch information
1 parent
57d2a0b
commit 967443a
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import fs from 'fs'; | ||
import yaml from 'js-yaml'; | ||
import path from 'path'; | ||
import { z } from "zod"; | ||
|
||
const AEP_LOC = process.env.AEP_LOCATION!; | ||
|
||
const Config = z.object({ | ||
hero: z.object({ | ||
buttons: z.array(z.object({ | ||
text: z.string(), | ||
href: z.string(), | ||
})), | ||
shortcuts: z.array(z.object({ | ||
title: z.string(), | ||
description: z.string(), | ||
button: z.object({ | ||
text: z.string(), | ||
href: z.string(), | ||
}), | ||
})), | ||
}), | ||
site: z.object({ | ||
ga_tag: z.string(), | ||
}), | ||
urls: z.object({ | ||
site: z.string(), | ||
repo: z.string(), | ||
}), | ||
}); | ||
|
||
type Config = z.infer<typeof Config>; | ||
|
||
function loadConfigFiles(...fileNames: string[]): Config { | ||
const config = {}; | ||
|
||
fileNames.forEach((fileName) => { | ||
try { | ||
const filePath = path.join(AEP_LOC, "config", fileName); | ||
const fileContents = fs.readFileSync(filePath, 'utf8'); | ||
const parsedYaml = yaml.load(fileContents); | ||
config[fileName.replace('.yaml', '')] = parsedYaml; | ||
} catch (error) { | ||
console.error(`Error loading ${fileName}:`, error); | ||
} | ||
}); | ||
|
||
return Config.parse(config); | ||
} | ||
|
||
export default loadConfigFiles; |