/** * Pre-generates Bible verse data for all rosary mystery references. * Run with: npx vite-node scripts/generate-mystery-verses.ts */ import { writeFileSync } from 'fs'; import { resolve } from 'path'; import { lookupReference } from '../src/lib/server/bible'; import { mysteryReferences } from '../src/lib/data/mysteryDescriptions'; import type { MysteryDescription, VerseData } from '../src/lib/data/mysteryDescriptions'; const tsvPath = resolve('static/allioli.tsv'); const mysteryDescriptions: Record = {}; for (const [mysteryType, references] of Object.entries(mysteryReferences)) { const descriptions: MysteryDescription[] = []; for (const ref of references) { const result = lookupReference(ref.reference, tsvPath); let text = ''; let verseData: VerseData | null = null; if (result && result.verses.length > 0) { text = `«${result.verses.map((v) => v.text).join(' ')}»`; verseData = { book: result.book, chapter: result.chapter, verses: result.verses }; } else { console.warn(`No verses found for: ${ref.reference}`); } descriptions.push({ title: ref.title, reference: ref.reference, text, verseData }); } mysteryDescriptions[mysteryType] = descriptions; } const output = `// Auto-generated by scripts/generate-mystery-verses.ts — do not edit manually import type { MysteryDescription } from './mysteryDescriptions'; export const mysteryVerseData: Record = ${JSON.stringify(mysteryDescriptions, null, '\t')}; `; const outPath = resolve('src/lib/data/mysteryVerseData.ts'); writeFileSync(outPath, output, 'utf-8'); console.log(`Wrote mystery verse data to ${outPath}`);