kin/scripts/rebuild-frontend.sh

31 lines
1.2 KiB
Bash
Executable file

#!/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 <project_id>
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.
# API is managed by launchctl with KeepAlive=true — just kill it, launchctl restarts it.
# 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] Restarting API server (PID: $API_PID) — launchctl will auto-restart ..."
kill "$API_PID" 2>/dev/null || true
echo "[rebuild-frontend] API server restarted (launchctl KeepAlive=true)."
else
echo "[rebuild-frontend] API server not running; skipping restart."
fi