42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
#!/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, '..');
|
|
|
|
const { stringifyCanonical } = await import(path.join(root, 'shared/src/canonical-json.ts'));
|
|
|
|
const files = [
|
|
'site-context.json',
|
|
'content/events.json',
|
|
'config/sms-sites.json',
|
|
...fs.readdirSync(path.join(root, 'content/sections'))
|
|
.filter(f => f.endsWith('.json'))
|
|
.map(f => `content/sections/${f}`),
|
|
];
|
|
|
|
const errors = [];
|
|
console.log('Checking canonical JSON format...');
|
|
|
|
for (const rel of files) {
|
|
const abs = path.join(root, rel);
|
|
const raw = fs.readFileSync(abs, 'utf-8');
|
|
const parsed = JSON.parse(raw);
|
|
const canonical = stringifyCanonical(parsed);
|
|
if (raw === canonical) {
|
|
console.log(` ✓ ${rel}`);
|
|
} else {
|
|
errors.push(rel);
|
|
}
|
|
}
|
|
|
|
if (errors.length > 0) {
|
|
console.error('\n✗ Non-canonical files (run `node scripts/canonicalize.js` to fix):');
|
|
errors.forEach(e => console.error(` ${e}`));
|
|
process.exit(1);
|
|
} else {
|
|
console.log('\n✓ All files are canonical.');
|
|
}
|