Files
spiceflow/script/dev

101 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Development script - runs backend REPL with auto-reload and frontend
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
BACKEND_PID=""
FRONTEND_PID=""
NREPL_PORT=7888
cleanup() {
echo -e "\n${YELLOW}Shutting down...${NC}"
# Kill backend and all its children
if [ -n "$BACKEND_PID" ]; then
pkill -P $BACKEND_PID 2>/dev/null || true
kill $BACKEND_PID 2>/dev/null || true
fi
# Kill frontend and all its children
if [ -n "$FRONTEND_PID" ]; then
pkill -P $FRONTEND_PID 2>/dev/null || true
kill $FRONTEND_PID 2>/dev/null || true
fi
# Also kill any orphaned processes on our ports
fuser -k 3000/tcp 2>/dev/null || true
fuser -k 5173/tcp 2>/dev/null || true
fuser -k $NREPL_PORT/tcp 2>/dev/null || true
wait 2>/dev/null || true
echo -e "${GREEN}Stopped${NC}"
# Restore terminal
stty sane 2>/dev/null || true
exit 0
}
trap cleanup SIGINT SIGTERM SIGHUP EXIT
echo -e "${BLUE}=== Starting Spiceflow Development Environment ===${NC}\n"
# Start backend REPL with auto-reload
echo -e "${GREEN}Starting backend REPL with auto-reload...${NC}"
cd "$ROOT_DIR/server"
# Start nREPL server and run (go) to start app with file watcher
clj -M:dev -e "
(require 'nrepl.server)
(def server (nrepl.server/start-server :port $NREPL_PORT))
(println \"nREPL server started on port $NREPL_PORT\")
(require 'user)
(user/go)
;; Block forever to keep the process running
@(promise)
" &
BACKEND_PID=$!
# Wait for backend to be ready
echo -e "${YELLOW}Waiting for backend...${NC}"
until curl -s http://localhost:3000/api/health > /dev/null 2>&1; do
sleep 1
done
echo -e "${GREEN}Backend ready on http://localhost:3000${NC}"
echo -e "${GREEN}nREPL available on port $NREPL_PORT${NC}"
echo -e "${GREEN}Auto-reload enabled - editing .clj files will trigger reload${NC}"
# Start frontend
echo -e "${GREEN}Starting frontend server...${NC}"
cd "$ROOT_DIR/client"
npm run dev &
FRONTEND_PID=$!
# Wait for frontend to be ready
echo -e "${YELLOW}Waiting for frontend...${NC}"
until curl -sk https://localhost:5173 > /dev/null 2>&1; do
sleep 1
done
echo -e "${GREEN}Frontend ready on https://0.0.0.0:5173${NC}"
# Get local IP for phone access
LOCAL_IP=$(hostname -I | awk '{print $1}')
echo -e "\n${BLUE}=== Spiceflow Development Environment Ready ===${NC}"
echo -e "${GREEN}Backend:${NC} http://localhost:3000"
echo -e "${GREEN}nREPL:${NC} localhost:$NREPL_PORT"
echo -e "${GREEN}Frontend:${NC} https://localhost:5173"
echo -e "${GREEN}Phone:${NC} https://${LOCAL_IP}:5173"
echo -e "\n${YELLOW}Auto-reload is active. Edit any .clj file to trigger reload.${NC}"
echo -e "Press Ctrl+C to stop\n"
# Wait for processes
wait