#!/usr/bin/env bash # rebuild-frontend — post-pipeline hook for Kin. # # Triggered automatically after pipeline_completed when web/frontend/* modules # were touched. Builds the Vue 3 frontend and restarts the API server. # # Registration (one-time): # kin hook setup --project set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" FRONTEND_DIR="$PROJECT_ROOT/web/frontend" echo "[rebuild-frontend] Building frontend in $FRONTEND_DIR ..." cd "$FRONTEND_DIR" npm run build echo "[rebuild-frontend] Build complete." # Restart API server if it's currently running. # pgrep returns 1 if no match; || true prevents set -e from exiting. API_PID=$(pgrep -f "uvicorn web.api" 2>/dev/null || true) if [ -n "$API_PID" ]; then echo "[rebuild-frontend] Stopping API server (PID: $API_PID) ..." kill "$API_PID" 2>/dev/null || true # Wait for port 8420 to free up (up to 5 s) for i in $(seq 1 5); do pgrep -f "uvicorn web.api" > /dev/null 2>&1 || break sleep 1 done echo "[rebuild-frontend] Starting API server ..." cd "$PROJECT_ROOT" nohup python -m uvicorn web.api:app --port 8420 >> /tmp/kin-api.log 2>&1 & echo "[rebuild-frontend] API server started (PID: $!)." else echo "[rebuild-frontend] API server not running; skipping restart." fi