UNPKG

@paroicms/server

Version:
31 lines 1.15 kB
import { isResizeRule, messageOf, } from "@paroicms/public-anywhere-lib"; import { jsonTypeValidator } from "@paroicms/public-server-lib"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; export async function readThemeConfFile(themeDir) { const themeFile = join(themeDir, "theme.json"); try { const content = await readFile(themeFile, "utf-8"); const data = JSON.parse(content); const result = jsonTypeValidator.validate("JtThemeConf", data); if (!result.valid) throw new Error(result.error ?? "(missing message)"); return formatThemeConf(data); } catch (error) { throw new Error(`invalid theme configuration '${themeFile}': ${messageOf(error)} `); } } export function formatThemeConf(val) { val.fTextImages.forEach(checkResizeRule); const pixelRatio = val.pixelRatio ?? 1; return { fTextImageResizeRules: val.fTextImages, pixelRatio, }; } function checkResizeRule(val) { if (!isResizeRule(val)) throw new Error(`invalid image size '${val}'`); } //# sourceMappingURL=theme-conf-reader.js.map