Files
attack-defense-platform/panel/check_ui_js.js
T

21 lines
864 B
JavaScript
Raw Normal View History

// Extract every <script> block from index.html and syntax-check each with node.
const fs = require('fs');
const { execFileSync } = require('child_process');
const html = fs.readFileSync('/opt/gemastik18-final/panel/static/index.html', 'utf8');
const re = /<script(?![^>]*\bsrc=)[^>]*>([\s\S]*?)<\/script>/gi;
let m, i = 0, bad = 0;
while ((m = re.exec(html)) !== null) {
i++;
const code = m[1];
const f = `/tmp/blk_${i}.js`;
fs.writeFileSync(f, code);
try {
execFileSync(process.execPath, ['--check', f], { stdio: 'pipe' });
console.log(` script #${i}: OK (${code.split('\n').length} lines)`);
} catch (e) {
bad++;
console.log(` script #${i}: SYNTAX ERROR -> ${e.stderr.toString().split('\n').slice(0, 6).join('\n')}`);
}
}
console.log(bad === 0 ? `\nAll ${i} inline script block(s) parse cleanly.` : `\n${bad} block(s) FAILED.`);