| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 构建人设图谱可视化
- 步骤:
- 1. 通过环境变量传递数据路径给 Vite
- 2. npm run build 打包 Vue 项目(数据会被内联)
- 3. 复制到输出目录
- """
- import os
- import shutil
- import subprocess
- import sys
- from pathlib import Path
- # 项目路径
- project_root = Path(__file__).parent.parent.parent
- sys.path.insert(0, str(project_root))
- from script.data_processing.path_config import PathConfig
- def main():
- config = PathConfig()
- viz_dir = Path(__file__).parent
- print(f"账号: {config.account_name}")
- print()
- # 1. 确定数据文件路径
- persona_graph_file = config.intermediate_dir / "人设图谱.json"
- print(f"数据文件: {persona_graph_file}")
- if not persona_graph_file.exists():
- print(f"错误: 数据文件不存在!")
- sys.exit(1)
- # 2. 检查是否需要安装依赖
- node_modules = viz_dir / "node_modules"
- if not node_modules.exists():
- print("\n安装依赖...")
- subprocess.run(["npm", "install"], cwd=viz_dir, check=True)
- # 3. 构建 Vue 项目(通过环境变量传递数据路径)
- print("\n构建 Vue 项目...")
- env = os.environ.copy()
- env["GRAPH_DATA_PATH"] = str(persona_graph_file.absolute())
- subprocess.run(["npm", "run", "build"], cwd=viz_dir, env=env, check=True)
- # 4. 复制到输出目录
- dist_html = viz_dir / "dist" / "index.html"
- output_file = config.intermediate_dir / "人设图谱可视化.html"
- print(f"\n输出: {output_file}")
- shutil.copy(dist_html, output_file)
- print("\n完成!")
- if __name__ == "__main__":
- main()
|