#!/usr/bin/env node // Verifies that every asset path in AssetsConstants.ts and index.html exists. // A wrong path builds fine and only 404s at runtime. import { existsSync, readFileSync, readdirSync } from 'node:fs'; import { join, dirname, extname } from 'node:path'; import { fileURLToPath } from 'node:url'; const srcDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'src'); const EXTENSIONS = new Set(['.ts', '.html', '.scss', '.json']); function* walk(dir) { for (const entry of readdirSync(dir, { withFileTypes: true })) { const path = join(dir, entry.name); if (entry.isDirectory()) { yield* walk(path); } else if (EXTENSIONS.has(extname(path)) && !path.endsWith('.spec.ts')) { yield path; } } } const missing = []; for (const file of walk(srcDir)) { const content = readFileSync(file, 'utf8'); for (const [, path] of content.matchAll(/\b(assets\/[\w./-]+)/g)) { if (!existsSync(join(srcDir, path))) { missing.push(`${file}: ${path}`); } } } if (missing.length > 0) { console.error(`Missing assets:\n${missing.join('\n')}`); process.exit(1); } console.log('All referenced assets exist.');