_check_cms_scoped.mjs 2.5 KB

1234567891011121314151617181920212223242526272829303132
  1. // P76 核验:作用域化门户 CSS + 门户 #cms 节原文(内联 v-html)
  2. import { readFileSync } from 'node:fs'
  3. import { fileURLToPath } from 'node:url'
  4. import { dirname, resolve } from 'node:path'
  5. import { JSDOM, VirtualConsole } from 'jsdom'
  6. const HERE = dirname(fileURLToPath(import.meta.url))
  7. const dist = resolve(HERE, '../../../release/web')
  8. const idx = readFileSync(dist + '/index.html', 'utf8')
  9. const jsFile = (idx.match(/src="([^"]+\.js)"/) || [])[1].replace(/^.*\//, '')
  10. const cssFile = (idx.match(/href="([^"]+\.css)"/) || [])[1].replace(/^.*\//, '')
  11. const code = readFileSync(dist + '/assets/' + jsFile, 'utf8')
  12. const css = readFileSync(dist + '/assets/' + cssFile, 'utf8')
  13. const fleet = readFileSync(resolve(HERE, '_fleet_fixture.json'), 'utf8')
  14. const vib = readFileSync(resolve(HERE, '_vibcms_fixture.json'), 'utf8')
  15. const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
  16. { url: 'http://127.0.0.1:28084/detail/v2#tab=vibration:portal_cms', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
  17. const w = dom.window
  18. w.onerror = (m) => console.log('WIN_ERR ' + String(m).slice(0, 160))
  19. w.fetch = async (u) => { const s = String(u); const body = /fleet/.test(s) ? fleet : (/vibcms/.test(s) ? vib : '{}')
  20. return { ok: true, status: 200, json: async () => JSON.parse(body), text: async () => body } }
  21. try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 140)) }
  22. for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('.portal-cms-scope')) break }
  23. const root = w.document.querySelector('#root') || w.document.body
  24. const scope = root.querySelector('.portal-cms-scope')
  25. const txt = (scope ? scope.textContent : '').replace(/\s+/g, ' ')
  26. const st = Array.from(root.querySelectorAll('style')).map((s) => s.textContent || '').join('\n')
  27. console.log('SCOPE ' + (scope ? 'Y' : 'N') + ' ELEMENTS ' + (scope ? scope.querySelectorAll('*').length : 0))
  28. console.log('SCOPED_CSS ' + /\.portal-cms-scope\s+\.hero/.test(st) + ' ROOT_AS_SCOPE ' + /\.portal-cms-scope\{--ground/.test(st.replace(/\s+/g, '')))
  29. console.log('HAS_HERO ' + /振动与 SCADA 联合分析/.test(txt) + ' HAS_LEAD ' + /六层模型/.test(txt))
  30. console.log('HAS_ORIG_ITEMS ' + /TCM 六采集窗|windcms|状态监测/.test(txt))
  31. console.log('HAS_LIVE ' + (/当前时间窗 · /.test(txt) && /需关注 \d+ 台/.test(txt)))
  32. console.log('CHIP_CLASS ' + (scope ? scope.querySelectorAll('.chip').length : 0))