#!/usr/bin/env node // Pre-deploy syntax guard for the served HTML pages. // // WHY: our pages carry large INLINE (skip ones with a src= attribute — those are external files, nothing inline). const re = /]*)>([\s\S]*?)<\/script\s*>/gi; let errors = 0; let blocks = 0; for (const f of files) { const html = fs.readFileSync(path.join(dir, f), 'utf8'); re.lastIndex = 0; let m; while ((m = re.exec(html))) { if (/\bsrc\s*=/i.test(m[1] || '')) continue; // external script blocks++; const code = m[2]; // File line where this block's body starts, so the reported line is file-relative (not block-relative). const openTagEnd = m.index + m[0].indexOf('>') + 1; const startLine = html.slice(0, openTagEnd).split('\n').length - 1; // 0-indexed offset try { new vm.Script(code, { filename: f, lineOffset: startLine }); } catch (e) { errors++; const loc = (String(e.stack || '').split('\n')[0] || '').trim(); // e.g. "home.html:4398" console.error('[check-syntax] ' + f + ' — ' + (e.message || 'syntax error') + (loc && /:\d+$/.test(loc) ? (' @ ' + loc) : (' (inline