A simple, folder-driven static-site engine.
bun ssg fs
at dev 27 lines 649 B view raw
1/** 2 * Webette version helper. 3 */ 4 5import { readFileSync } from "node:fs"; 6import { fileURLToPath } from "node:url"; 7 8let cachedVersion: string | undefined; 9 10export function getVersion(): string { 11 if (cachedVersion) return cachedVersion; 12 const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url)); 13 14 try { 15 const raw = readFileSync(pkgPath, "utf8"); 16 const parsed = JSON.parse(raw) as { version?: unknown }; 17 if (typeof parsed?.version === "string") { 18 cachedVersion = parsed.version; 19 return cachedVersion; 20 } 21 } catch { 22 // fallback below 23 } 24 25 cachedVersion = "unknown"; 26 return cachedVersion; 27}