25 lines
1014 B
JavaScript
25 lines
1014 B
JavaScript
// Syntax-check every inline <script> block across all panel static pages.
|
|||
|
|
const fs = require('fs');
|
||
|
|
const { execFileSync } = require('child_process');
|
||
|
|
const files = ['static/index.html', 'static/team.html', 'static/guide.html'];
|
||
|
|
const base = '/opt/gemastik18-final/panel/';
|
||
|
|
let bad = 0, total = 0;
|
||
|
|
for (const f of files) {
|
||
|
|
const html = fs.readFileSync(base + f, 'utf8');
|
||
|
|
const re = /<script(?![^>]*\bsrc=)[^>]*>([\s\S]*?)<\/script>/gi;
|
||
|
|
let m, i = 0;
|
||
|
|
while ((m = re.exec(html)) !== null) {
|
||
|
|
i++; total++;
|
||
|
|
const p = `/tmp/chk_${f.replace(/\W/g, '_')}_${i}.js`;
|
||
|
|
fs.writeFileSync(p, m[1]);
|
||
|
|
try {
|
||
|
|
execFileSync(process.execPath, ['--check', p], { stdio: 'pipe' });
|
||
|
|
console.log(` OK ${f} block#${i}`);
|
||
|
|
} catch (e) {
|
||
|
|
bad++;
|
||
|
|
console.log(` FAIL ${f} block#${i}\n${e.stderr.toString().split('\n').slice(0, 5).join('\n')}`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
console.log(bad === 0 ? `\nAll ${total} script block(s) parse cleanly.` : `\n${bad}/${total} FAILED.`);
|
||
|
|
process.exit(bad ? 1 : 0);
|