Add logging
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { sectionFileSchema } from '@dynamic-sites/shared';
|
import { sectionFileSchema } from '@dynamic-sites/shared';
|
||||||
|
import { logger } from '../logger.js';
|
||||||
|
|
||||||
const REPO_ROOT = process.env.REPO_ROOT || '.';
|
const REPO_ROOT = process.env.REPO_ROOT || '.';
|
||||||
|
|
||||||
@@ -18,13 +19,25 @@ export function buildSectionManifest(): ManifestEntry[] {
|
|||||||
const sectionsDir = path.join(REPO_ROOT, 'content/sections');
|
const sectionsDir = path.join(REPO_ROOT, 'content/sections');
|
||||||
const manifest: ManifestEntry[] = [];
|
const manifest: ManifestEntry[] = [];
|
||||||
|
|
||||||
if (!fs.existsSync(sectionsDir)) return manifest;
|
if (!fs.existsSync(sectionsDir)) {
|
||||||
|
logger.warn({ event: 'manifest.dir_missing', path: sectionsDir }, 'Sections directory does not exist');
|
||||||
|
return manifest;
|
||||||
|
}
|
||||||
|
|
||||||
for (const file of fs.readdirSync(sectionsDir).filter(f => f.endsWith('.json'))) {
|
const files = fs.readdirSync(sectionsDir).filter(f => f.endsWith('.json'));
|
||||||
|
logger.info({ event: 'manifest.scan', path: sectionsDir, fileCount: files.length, files }, 'Scanning sections directory');
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const filePath = path.join(sectionsDir, file);
|
||||||
try {
|
try {
|
||||||
const raw = JSON.parse(fs.readFileSync(path.join(sectionsDir, file), 'utf-8'));
|
const rawText = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const raw = JSON.parse(rawText);
|
||||||
const parsed = sectionFileSchema.safeParse(raw);
|
const parsed = sectionFileSchema.safeParse(raw);
|
||||||
if (!parsed.success) continue;
|
|
||||||
|
if (!parsed.success) {
|
||||||
|
logger.warn({ event: 'manifest.parse_failed', file, errors: parsed.error.issues.map(i => `${i.path.join('.')}: ${i.message}`) }, 'Section file failed schema validation');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const s = parsed.data;
|
const s = parsed.data;
|
||||||
const entry: ManifestEntry = {
|
const entry: ManifestEntry = {
|
||||||
@@ -39,7 +52,9 @@ export function buildSectionManifest(): ManifestEntry[] {
|
|||||||
if (s.type === 'text') entry.heading = s.heading;
|
if (s.type === 'text') entry.heading = s.heading;
|
||||||
|
|
||||||
manifest.push(entry);
|
manifest.push(entry);
|
||||||
} catch { /* skip bad files */ }
|
} catch (err) {
|
||||||
|
logger.error({ event: 'manifest.read_error', file, error: (err as Error).message }, 'Failed to read section file');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also add events.json
|
// Also add events.json
|
||||||
@@ -51,5 +66,7 @@ export function buildSectionManifest(): ManifestEntry[] {
|
|||||||
visible: true,
|
visible: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info({ event: 'manifest.built', sectionCount: manifest.length }, 'Manifest built');
|
||||||
|
|
||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user