// Regenerates public/fonts/manifest.json from the TTFs under public/fonts//. // Run: node scripts/fonts/build-manifest.mjs import { existsSync, writeFileSync } from "node:fs"; import path from "node:path"; import { FONTS_DIR, MANIFEST_PATH, familyFolders, inspectFont, ttfFiles } from "./lib.mjs"; const families = []; for (const folder of familyFolders()) { const files = ttfFiles(folder); if (files.length === 0) continue; const inspected = files.map((file) => inspectFont(folder, file)); const names = new Set(inspected.map((f) => f.familyName)); if (names.size !== 1) { throw new Error(`${folder}: mixed family names ${[...names].join(", ")}`); } const licenseFile = "OFL.txt"; if (!existsSync(path.join(FONTS_DIR, folder, licenseFile))) { throw new Error(`${folder}: missing ${licenseFile}`); } const fonts = inspected .map((f) => f.info) .sort((a, b) => a.weight - b.weight || a.style.localeCompare(b.style) || a.file.localeCompare(b.file)); families.push({ family: [...names][0], folder, license: "OFL-1.1", licenseFile, fonts }); } writeFileSync(MANIFEST_PATH, `${JSON.stringify({ version: 1, families }, null, 2)}\n`); console.log( `manifest.json: ${families.length} families, ${families.reduce((n, f) => n + f.fonts.length, 0)} fonts`, );