/** * 一次性自检脚本:核对页面元素 id 与脚本引用是否一致。 */ const fs = require('node:fs'); const path = require('node:path'); const root = path.join(__dirname, '..'); const html = fs.readFileSync(path.join(root, 'public', 'index.html'), 'utf8'); const js = fs.readFileSync(path.join(root, 'public', 'app.js'), 'utf8'); const css = fs.readFileSync(path.join(root, 'public', 'style.css'), 'utf8'); const ids = new Set([...html.matchAll(/id="([^"]+)"/g)].map((m) => m[1])); const used = new Set([...js.matchAll(/\$\('#([a-zA-Z0-9_-]+)'\)/g)].map((m) => m[1])); const missing = [...used].filter((id) => !ids.has(id)); console.log('页面 id 数量:', ids.size); console.log('脚本引用 id 数量:', used.size); console.log('缺失的 id:', missing.length ? missing.join(', ') : '无'); const classes = ['card', 'metrics', 'panel', 'switch', 'state', 'log-line']; console.log('CSS 关键类存在:', classes.every((name) => css.includes(`.${name}`))); // 检查 CSS 花括号配对 const open = (css.match(/{/g) || []).length; const close = (css.match(/}/g) || []).length; console.log('CSS 花括号配对:', open === close, `(${open}/${close})`);