dump_ssr.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * 打印 Vue SSR 出来的 fault 页签里含 "前三" 的那段 HTML(对照旧页面,定位差在哪)。
  3. * 用法:node tools/dump_ssr.mjs fault 前三
  4. */
  5. import { JSDOM } from 'jsdom'
  6. import { pathToFileURL } from 'node:url'
  7. import { resolve, dirname } from 'node:path'
  8. import { fileURLToPath } from 'node:url'
  9. const HERE = dirname(fileURLToPath(import.meta.url))
  10. const GATEWAY = 'http://127.0.0.1:28084'
  11. const TAB = process.argv[2] || 'fault'
  12. const NEEDLE = process.argv[3] || '前三'
  13. const data = await (await fetch(`${GATEWAY}/detail/api/fleet`)).json()
  14. const entry = pathToFileURL(resolve(HERE, '../target/ssr/entry-server.js')).href
  15. const html = await (await import(entry)).renderTab(data, TAB)
  16. const dom = new JSDOM(`<div id="wrap">${html}</div>`)
  17. const wrap = dom.window.document.getElementById('wrap')
  18. for (const p of Array.from(wrap.querySelectorAll('p'))) {
  19. if (p.textContent.includes(NEEDLE)) {
  20. console.log('--- Vue SSR <p> ---')
  21. console.log(p.outerHTML.replace(/\s+/g, ' ').slice(0, 700))
  22. console.log(' 文本节点:')
  23. for (const c of p.childNodes) {
  24. if (c.nodeType === 3 && c.textContent.trim()) console.log(' text:', JSON.stringify(c.textContent))
  25. else if (c.nodeType === 1) console.log(' <' + c.tagName.toLowerCase() + '>', JSON.stringify(c.textContent))
  26. }
  27. }
  28. }