#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.resolve(__dirname, '..'); // Dynamic import of shared schemas const { siteContextSchema, sectionFileSchema, eventsFileSchema, smsSitesConfigSchema, } = await import(path.join(root, 'shared/src/schemas/index.ts')); const errors = []; function validate(filePath, schema, label) { const rel = path.relative(root, filePath); try { const raw = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const result = schema.safeParse(raw); if (!result.success) { errors.push(`${rel}: ${result.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ')}`); } else { console.log(` āœ“ ${rel}`); } } catch (e) { errors.push(`${rel}: ${e.message}`); } } console.log('Validating content...'); // site-context.json validate(path.join(root, 'site-context.json'), siteContextSchema, 'site-context'); // content/events.json validate(path.join(root, 'content/events.json'), eventsFileSchema, 'events'); // config/sms-sites.json validate(path.join(root, 'config/sms-sites.json'), smsSitesConfigSchema, 'sms-sites'); // content/sections/*.json const sectionsDir = path.join(root, 'content/sections'); if (fs.existsSync(sectionsDir)) { for (const file of fs.readdirSync(sectionsDir).filter(f => f.endsWith('.json'))) { validate(path.join(sectionsDir, file), sectionFileSchema, file); } } if (errors.length > 0) { console.error('\nāœ— Validation failed:'); errors.forEach(e => console.error(` ${e}`)); process.exit(1); } else { console.log('\nāœ“ All content valid.'); }