#!/bin/bash # # ZCLAW Development Quick Start Script # # Usage: # ./scripts/quick-start.sh [options] # # Options: # --skip-backend Skip backend startup (assume already running) # --desktop-only Start desktop only # --stop Stop all services # --help Show this help message # set -e PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)" SKIP_BACKEND=false DESKTOP_ONLY=false STOP_SERVICES=false # Parse arguments for arg in "$@"; do case $arg in --skip-backend) SKIP_BACKEND=true shift ;; --desktop-only) DESKTOP_ONLY=true shift ;; --stop) STOP_SERVICES=true shift ;; --help) echo "ZCLAW Development Quick Start Script" echo "" echo "Usage: $0 [options]" echo "" echo "Options:" echo " --skip-backend Skip backend startup" echo " --desktop-only Start desktop only" echo " --stop Stop all services" echo " --help Show this help" exit 0 ;; *) echo "Unknown option: $arg" exit 1 ;; esac done # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' # No Color # Output functions step() { echo -e "\n${CYAN}[STEP]${NC} $1" } success() { echo -e "${GREEN}[OK]${NC} $1" } warn() { echo -e "${YELLOW}[WARN]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" } # Stop services if [ "$STOP_SERVICES" = true ]; then step "Stopping all services..." # Kill OpenFang processes pkill -f "openfang" 2>/dev/null || true # Kill Vite processes pkill -f "vite" 2>/dev/null || true # Kill Tauri processes pkill -f "tauri" 2>/dev/null || true success "All services stopped" exit 0 fi echo -e "${CYAN}========================================${NC}" echo -e "${CYAN} ZCLAW Development Quick Start${NC}" echo -e "${CYAN}========================================${NC}" # 1. Check Node.js step "Checking Node.js..." if ! command -v node &> /dev/null; then error "Node.js not found" echo "Please install from https://nodejs.org" exit 1 fi NODE_VERSION=$(node -v | sed 's/v//') MAJOR_VERSION=$(echo "$NODE_VERSION" | cut -d. -f1) if [ "$MAJOR_VERSION" -lt 18 ]; then error "Node.js version too low: v$NODE_VERSION (requires 18+)" echo "Please upgrade from https://nodejs.org" exit 1 fi success "Node.js $(node -v)" # 2. Check pnpm step "Checking pnpm..." if ! command -v pnpm &> /dev/null; then warn "pnpm not found, installing..." npm install -g pnpm if [ $? -ne 0 ]; then error "Failed to install pnpm" exit 1 fi fi success "pnpm $(pnpm -v)" # 3. Check and install dependencies step "Checking dependencies..." if [ ! -d "$PROJECT_ROOT/node_modules" ]; then echo "Installing root dependencies..." cd "$PROJECT_ROOT" pnpm install fi if [ ! -d "$PROJECT_ROOT/desktop/node_modules" ]; then echo "Installing desktop dependencies..." cd "$PROJECT_ROOT/desktop" pnpm install fi success "Dependencies ready" # 4. Check/Start backend if [ "$SKIP_BACKEND" = false ] && [ "$DESKTOP_ONLY" = false ]; then step "Checking backend service..." BACKEND_RUNNING=false if curl -s --connect-timeout 2 "http://127.0.0.1:50051/api/health" > /dev/null 2>&1; then BACKEND_RUNNING=true success "Backend service already running" fi if [ "$BACKEND_RUNNING" = false ]; then echo "Starting OpenFang backend..." STARTED=false # Method 1: Use openfang CLI if command -v openfang &> /dev/null; then openfang start & STARTED=true fi # Method 2: Use the project's start script if [ "$STARTED" = false ] && [ -f "$PROJECT_ROOT/start-all.sh" ]; then "$PROJECT_ROOT/start-all.sh" & STARTED=true fi if [ "$STARTED" = false ]; then error "Cannot start backend service" echo "Please start OpenFang manually:" echo " openfang start" exit 1 fi # Wait for backend echo "Waiting for backend to start..." RETRIES=0 MAX_RETRIES=15 while [ $RETRIES -lt $MAX_RETRIES ]; do sleep 1 if curl -s --connect-timeout 2 "http://127.0.0.1:50051/api/health" > /dev/null 2>&1; then success "Backend started successfully" break fi RETRIES=$((RETRIES + 1)) printf "." done if [ $RETRIES -ge $MAX_RETRIES ]; then error "Backend startup timeout" echo "Please check if OpenFang is properly installed" exit 1 fi fi fi # 5. Start development environment step "Starting development environment..." cd "$PROJECT_ROOT" if [ "$DESKTOP_ONLY" = true ]; then echo "Starting desktop only..." pnpm desktop else echo "Starting full development environment..." pnpm start:dev fi