import { readFileSync, readdirSync } from 'fs'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; const __dirname = dirname(fileURLToPath(import.meta.url)); const root = join(__dirname, '..'); const jsDir = join(root, 'js'); const files = readdirSync(jsDir).filter(f => f.endsWith('.js')); let errors = 0; for (const file of files) { const path = join(jsDir, file); const source = readFileSync(path, 'utf-8'); // Basic sanity: file is non-empty and has balanced braces if (source.length < 10) { console.log(` FAIL ${file}: too small`); errors++; continue; } const openBraces = (source.match(/{/g) || []).length; const closeBraces = (source.match(/}/g) || []).length; if (openBraces !== closeBraces) { console.log(` FAIL ${file}: unbalanced braces (${openBraces} open, ${closeBraces} close)`); errors++; continue; } const openParens = (source.match(/\(/g) || []).length; const closeParens = (source.match(/\)/g) || []).length; if (openParens !== closeParens) { console.log(` FAIL ${file}: unbalanced parentheses`); errors++; continue; } console.log(` PASS ${file}`); } const html = readFileSync(join(root, 'index.html'), 'utf-8'); if (html.includes(' 0) process.exit(1);