Skip to content

Commit

Permalink
fix: 🧩 修复导出html无效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Plumbiu committed Sep 9, 2023
1 parent cf68229 commit 91dc6a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-pugs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'truth-cli': patch
---

修复导出html无效问题
5 changes: 4 additions & 1 deletion packages/cli/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export async function genFile(depth: any, type: FileType, p: string) {
const html = brotliDecompressSync(brHTML).toString()
writeFileSync(
writePath,
html.replace('fetch("relations.json")', `new Response('${JSON.stringify(relations).replace(/\\/g, '/')}')`),
html.replace(
'fetch("base.json")',
`new Response('${JSON.stringify(relations).replace(/\\/g, '/')}')`,
),
)
}
logFinished(Date.now() - begin, writePath)
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function initChart(_echart: ECharts, _relation: Relations) {
circulation = data.circulation
relations = data.relations
}
worker.postMessage('begin')
worker.postMessage(_relation)
const { nodes, links } = genGraph(_relation.__root__)
_echart.setOption(loadGraph(graphNodes = nodes, graphLinks = links))
echart = _echart
Expand Down
13 changes: 10 additions & 3 deletions packages/web/src/utils/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { genCirculation, genTree, genVersions } from '@truth-cli/core'
import type { Relations } from '@truth-cli/shared'

globalThis.addEventListener('message', async () => {
const relationsJSON = await fetch('http://localhost:3003/relations.json')
const relations = await relationsJSON.json()
globalThis.addEventListener('message', async (e) => {
let relations: Relations
if (Object.keys(e.data).length > 2) {
relations = e.data
}
else {
const relationsJSON = await fetch('http://localhost:3003/relations.json')
relations = await relationsJSON.json()
}

globalThis.postMessage({
relations,
Expand Down

1 comment on commit 91dc6a3

@vercel
Copy link

@vercel vercel bot commented on 91dc6a3 Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.