使用本机 graphify CLI 强制重建 backend/web-admin 图谱;脚本改为优先走 PATH 中的 graphify。 Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.1 KiB
Bash
Executable File
80 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# update-graph.sh — 增量更新知识图谱
|
|
# 用法:
|
|
# ./scripts/update-graph.sh # 更新前后端
|
|
# ./scripts/update-graph.sh backend # 只更新后端
|
|
# ./scripts/update-graph.sh frontend # 只更新前端
|
|
#
|
|
# 由 AI Agent 在完成代码修改后自动调用,或手动执行。
|
|
|
|
set -euo pipefail
|
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
# 优先使用 PATH 中的 graphify;其次尝试本机常见 Python
|
|
run_graphify() {
|
|
if command -v graphify >/dev/null 2>&1; then
|
|
graphify "$@"
|
|
return
|
|
fi
|
|
local py
|
|
for py in \
|
|
"${GRAPHIFY_PYTHON:-}" \
|
|
"$ROOT_DIR/backend/venv/bin/python" \
|
|
"$(command -v python3 2>/dev/null || true)" \
|
|
"/Users/zlwu/.pyenv/versions/3.12.13/bin/python"
|
|
do
|
|
[ -n "$py" ] && [ -x "$py" ] || continue
|
|
if "$py" -m graphify --help >/dev/null 2>&1; then
|
|
"$py" -m graphify "$@"
|
|
return
|
|
fi
|
|
done
|
|
echo "[graphify] 未找到可用的 graphify。请安装 CLI(如: pipx install graphifyy)或设置 GRAPHIFY_PYTHON。"
|
|
exit 1
|
|
}
|
|
|
|
# 更新单个项目的图谱
|
|
update_graph() {
|
|
local name="$1"
|
|
local label="$2"
|
|
|
|
echo ""
|
|
echo "=== 更新 ${label} 知识图谱 (${name}) ==="
|
|
|
|
if [ ! -d "$ROOT_DIR/$name" ]; then
|
|
echo "[graphify] 目录不存在: $ROOT_DIR/$name"
|
|
return 1
|
|
fi
|
|
|
|
run_graphify update "$ROOT_DIR/$name" --force
|
|
|
|
echo "[graphify] ${label} 图谱更新完成 ✓"
|
|
}
|
|
|
|
# ---- Main ----
|
|
TARGET="${1:-all}"
|
|
|
|
echo "╔══════════════════════════════════════╗"
|
|
echo "║ shanxia2.0 知识图谱增量更新工具 ║"
|
|
echo "╚══════════════════════════════════════╝"
|
|
|
|
case "$TARGET" in
|
|
backend)
|
|
update_graph "backend" "后端"
|
|
;;
|
|
frontend)
|
|
update_graph "web-admin" "前端"
|
|
;;
|
|
all|"")
|
|
update_graph "backend" "后端"
|
|
update_graph "web-admin" "前端"
|
|
;;
|
|
*)
|
|
echo "用法: $0 [backend|frontend|all]"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo ""
|
|
echo "✅ 知识图谱更新完毕。HTML 可视化: */graphify-out/graph.html"
|