-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.mjs
39 lines (36 loc) · 1.01 KB
/
theme.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { resolve } from "path"
import { readFile } from "fs/promises"
import { resolveTemplates, updateTemplatesContext } from "./templates.mjs"
/**
* @typedef ThemeData
* @prop {string} name
* @prop {string} version
* @prop {string} repo
* @prop {Record<string, string>} templates
* @prop {Record<string, string>} [messages]
* @prop {Record<string, any>} [variables]
* @prop {Record<string, any>} [context]
*/
/**
*
* @param {string} root
* @returns {Promise<ThemeData>}
*/
export async function parseThemeData (root = ".") {
const theme = await loadThemeData(root)
if (theme.context) {
updateTemplatesContext(theme.templates, theme.context)
}
return theme
}
/**
*
* @param {string} root
* @returns {Promise<ThemeData>}
*/
export async function loadThemeData (root = ".") {
const themeData = await readFile(resolve(root, "theme.json"), { encoding: "utf-8" })
const theme = JSON.parse(themeData)
const templates = await resolveTemplates(resolve(root, "templates"))
return { ...theme, templates }
}