27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { parseEventSource } from '../src/data/event-parser';
|
|
import { validateEventCollection } from '../src/data/event-schema';
|
|
|
|
const eventDirectory = resolve(process.cwd(), 'content/events');
|
|
const eventFiles = readdirSync(eventDirectory).filter((file) => file.endsWith('.md')).sort();
|
|
|
|
if (eventFiles.length === 0) {
|
|
throw new Error(`No event Markdown files found in ${eventDirectory}`);
|
|
}
|
|
|
|
const events = eventFiles.map((file) => {
|
|
const filePath = resolve(eventDirectory, file);
|
|
const event = parseEventSource(readFileSync(filePath, 'utf8'), file);
|
|
const posterPath = resolve(eventDirectory, event.poster);
|
|
|
|
if (!posterPath.startsWith(`${eventDirectory}/`) || !existsSync(posterPath)) {
|
|
throw new Error(`${file}: poster does not exist next to the event Markdown file: ${event.poster}`);
|
|
}
|
|
|
|
return event;
|
|
});
|
|
|
|
validateEventCollection(events);
|
|
console.log(`Validated ${events.length} event file${events.length === 1 ? '' : 's'}.`);
|