realKnowledgeGraph.mjs
809 Bytes
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
export const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../../..',
)
// docs/generated 由 knowledge:build 生成、不入库;快照缺省时现场构建,
// 否则在 fresh clone 上所有读真实图谱的测试都会失败。
export async function loadRealKnowledgeGraph() {
const snapshot = path.join(projectRoot, 'docs/generated/knowledge-graph.json')
if (fs.existsSync(snapshot)) {
return JSON.parse(fs.readFileSync(snapshot, 'utf8'))
}
const { buildKnowledgeGraph } = await import(
pathToFileURL(path.join(projectRoot, 'scripts/knowledge-graph/build-knowledge-graph.mjs'))
)
return buildKnowledgeGraph({ rootDir: projectRoot })
}