#!/bin/sh
# 原型设计系统守门闸（本地 pre-commit）。
# 仅当本次提交动了原型（design/prototype/）时跑 check-ds.mjs 的 12 道检查；
# 任一违规 → 阻止提交。临时跳过：git commit --no-verify。
#
# 安装（每台机器一次，把仓库内本脚本接到 git 钩子）：
#   sh scripts/hooks/install.sh
root="$(git rev-parse --show-toplevel)"
gate="$root/design/prototype/tools/check-ds.mjs"

# 没动原型 → 直接放行
if ! git diff --cached --name-only | grep -q '^design/prototype/'; then
  exit 0
fi

if [ ! -f "$gate" ]; then
  echo "[ds-gate] ⚠ 找不到 $gate，跳过设计系统检查。"
  exit 0
fi

echo "[ds-gate] 原型有改动，跑设计系统守门闸（12 道）…"
if ! node "$gate" >/dev/null 2>&1; then
  echo "[ds-gate] ✗ 设计系统检查未通过，提交已阻止。"
  echo "[ds-gate]   详情：node design/prototype/tools/check-ds.mjs"
  echo "[ds-gate]   跳过：git commit --no-verify"
  exit 1
fi
echo "[ds-gate] ✓ 设计系统 12 道闸全过。"
exit 0
