kin/scripts/rebuild-frontend.sh

41 lines
1.6 KiB
Bash
Raw Normal View History

#!/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"
2026-03-19 21:53:31 +02:00
# KIN-122: auto npm install if package.json is newer than node_modules (or node_modules missing).
# This handles the case where agents add new imports/dependencies to package.json.
if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then
echo "[rebuild-frontend] package.json changed or node_modules missing — running npm install ..."
npm install
echo "[rebuild-frontend] npm install complete."
fi
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