#!/bin/bash # Tiny Workshop - Development Runner # Builds backend and runs the full application set -e # Exit on error SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" echo "🔧 Tiny Workshop Dev Runner" echo "==========================" echo "" # Colors for pretty output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Parse arguments BUILD_BACKEND=true BUILD_RUST=true RUN=true DEBUG_SERVER=false while [[ $# -gt 0 ]]; do case $1 in --skip-backend) BUILD_BACKEND=false shift ;; --skip-rust) BUILD_RUST=false shift ;; --build-only) RUN=false shift ;; --debug-server) DEBUG_SERVER=true shift ;; --help|-h) echo "Usage: ./dev.sh [options]" echo "" echo "Options:" echo " --skip-backend Skip building the backend executable" echo " --skip-rust Skip building the Rust frontend" echo " --build-only Build everything but don't run" echo " --debug-server Enable debug HTTP server (port 8765)" echo " --help, -h Show this help message" exit 0 ;; *) echo -e "${RED}Unknown option: $1${NC}" exit 1 ;; esac done # Step 1: Build backend if [ "$BUILD_BACKEND" = true ]; then echo -e "${BLUE}[1/3]${NC} Building backend standalone executable..." # Check if bun is installed if ! command -v bun &> /dev/null; then echo -e "${RED}Error: bun is not installed or not in PATH${NC}" echo "Install bun: https://bun.sh" exit 1 fi # Install dependencies if needed if [ ! -d "backend/node_modules" ]; then echo " Installing backend dependencies..." cd backend pnpm install cd .. fi # Build the standalone executable echo " Compiling TypeScript to standalone exe..." cd backend/packages/adapter bun run build cd ../../.. echo -e "${GREEN} ✓ Backend built: backend/packages/adapter/dist/tiny-workshop-backend.exe${NC}" else echo -e "${YELLOW}[1/3]${NC} Skipping backend build" fi echo "" # Step 2: Build Rust frontend if [ "$BUILD_RUST" = true ]; then echo -e "${BLUE}[2/3]${NC} Building Rust frontend..." cd tiny-workshop if [ "$DEBUG_SERVER" = true ]; then echo " Building with debug server enabled..." cargo build --package executor --features debug_server else cargo build --package executor fi cd .. echo -e "${GREEN} ✓ Rust frontend built${NC}" else echo -e "${YELLOW}[2/3]${NC} Skipping Rust build" fi echo "" # Step 3: Run the application if [ "$RUN" = true ]; then echo -e "${BLUE}[3/3]${NC} Starting Tiny Workshop..." # Clear old log file LOG_FILE="tiny-workshop/tiny-workshop.log" if [ -f "$LOG_FILE" ]; then rm "$LOG_FILE" echo " Cleared old log file" fi echo "" echo -e "${GREEN}════════════════════════════════════════${NC}" echo -e "${GREEN} Tiny Workshop is starting up!${NC}" if [ "$DEBUG_SERVER" = true ]; then echo -e "${GREEN} Debug server: http://localhost:8765${NC}" fi echo -e "${GREEN}════════════════════════════════════════${NC}" echo "" cd tiny-workshop if [ "$DEBUG_SERVER" = true ]; then cargo run --package executor --features debug_server else cargo run --package executor fi else echo -e "${YELLOW}[3/3]${NC} Build complete! Run with: cd tiny-workshop && cargo run --package executor" fi