From e2c5144b333989b19adc5d819f5d660a804e1af7 Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Thu, 5 Jun 2025 21:58:48 +0200 Subject: [PATCH 1/5] update dev.sh script --- scripts/dev.sh | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/scripts/dev.sh b/scripts/dev.sh index 0ed638c94..7abc6fa9a 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -6,6 +6,15 @@ set -e SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +# Detect OS +OS="unknown" +case "$(uname -s)" in + Linux*) OS="linux";; + Darwin*) OS="macos";; + CYGWIN*|MINGW*|MSYS*) OS="windows";; + *) OS="unknown";; +esac + # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' @@ -14,7 +23,9 @@ NC='\033[0m' # No Color print_header() { echo -e "${GREEN}๐Ÿš„ Hyperloop H10 Development Environment${NC}" - echo -e "${GREEN}=====================================>${NC}" + echo -e "${GREEN}=======================================${NC}" + echo -e "${YELLOW}OS: $OS${NC}" + echo "" } print_usage() { @@ -103,8 +114,37 @@ run_packet_sender() { } run_all_tmux() { + if [ "$OS" = "windows" ]; then + echo -e "${YELLOW}Note: Running all services in parallel on Windows...${NC}" + echo -e "${YELLOW}Use Ctrl+C to stop all services${NC}" + + # Start all services in background + (cd "$PROJECT_ROOT/backend/cmd" && go run .) & + PID_BACKEND=$! + + (cd "$PROJECT_ROOT/ethernet-view" && npm run dev) & + PID_ETHERNET=$! + + (cd "$PROJECT_ROOT/control-station" && npm run dev) & + PID_CONTROL=$! + + (cd "$PROJECT_ROOT/packet-sender" && go run .) & + PID_PACKET=$! + + echo -e "${GREEN}All services started. PIDs: Backend=$PID_BACKEND, Ethernet=$PID_ETHERNET, Control=$PID_CONTROL, Packet=$PID_PACKET${NC}" + + # Wait for any process to exit or Ctrl+C + wait + + # Kill all background processes + kill $PID_BACKEND $PID_ETHERNET $PID_CONTROL $PID_PACKET 2>/dev/null || true + echo -e "${YELLOW}All services stopped${NC}" + return + fi + if ! command -v tmux >/dev/null 2>&1; then - echo -e "${RED}Error: tmux is required to run all services${NC}" + echo -e "${RED}Error: tmux is required to run all services on Unix systems${NC}" + echo -e "${YELLOW}Tip: Install tmux or run services individually${NC}" exit 1 fi From 802f4ebcd859d944db55eecb2717c597aef234f9 Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Thu, 5 Jun 2025 21:58:55 +0200 Subject: [PATCH 2/5] add Windows development scripts --- scripts/dev.cmd | 225 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/dev.ps1 | 234 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 459 insertions(+) create mode 100644 scripts/dev.cmd create mode 100644 scripts/dev.ps1 diff --git a/scripts/dev.cmd b/scripts/dev.cmd new file mode 100644 index 000000000..9fd8f451e --- /dev/null +++ b/scripts/dev.cmd @@ -0,0 +1,225 @@ +@echo off +rem Development environment setup script for Windows + +setlocal enabledelayedexpansion + +rem Get script directory and project root +set SCRIPT_DIR=%~dp0 +set PROJECT_ROOT=%SCRIPT_DIR%.. + +rem Colors for output (using PowerShell for colored output) +set "RED=[31m" +set "GREEN=[32m" +set "YELLOW=[33m" +set "NC=[0m" + +:print_header +echo. +echo %GREEN%๐Ÿš„ Hyperloop H10 Development Environment%NC% +echo %GREEN%=======================================%NC% +echo %YELLOW%OS: Windows%NC% +echo. +goto :eof + +:print_usage +echo Usage: %0 [command] +echo. +echo Commands: +echo setup - Install all dependencies +echo backend - Run backend server +echo ethernet - Run ethernet-view dev server +echo control - Run control-station dev server +echo packet - Run packet-sender +echo all - Run all services in parallel +echo test - Run all tests +echo build - Build all components +echo. +goto :eof + +:check_dependencies +echo %YELLOW%Checking dependencies...%NC% + +where go >nul 2>&1 +if errorlevel 1 ( + echo %RED%Error: Go is not installed or not in PATH%NC% + exit /b 1 +) + +where node >nul 2>&1 +if errorlevel 1 ( + echo %RED%Error: Node.js is not installed or not in PATH%NC% + exit /b 1 +) + +where npm >nul 2>&1 +if errorlevel 1 ( + echo %RED%Error: npm is not installed or not in PATH%NC% + exit /b 1 +) + +echo %GREEN%โœ… All dependencies found%NC% +goto :eof + +:setup_project +echo %YELLOW%Setting up project dependencies...%NC% + +cd /d "%PROJECT_ROOT%" + +rem Build common-front first +echo ๐Ÿ“ฆ Building common-front... +cd common-front +call npm install +if errorlevel 1 exit /b 1 +call npm run build +if errorlevel 1 exit /b 1 + +rem Install ethernet-view dependencies +echo ๐Ÿ“ฆ Installing ethernet-view dependencies... +cd ..\ethernet-view +call npm install +if errorlevel 1 exit /b 1 + +rem Install control-station dependencies +echo ๐Ÿ“ฆ Installing control-station dependencies... +cd ..\control-station +call npm install +if errorlevel 1 exit /b 1 + +rem Download Go dependencies +echo ๐Ÿ“ฆ Downloading Go dependencies... +cd ..\backend +go mod download +if errorlevel 1 exit /b 1 + +cd ..\packet-sender +go mod download +if errorlevel 1 exit /b 1 + +echo %GREEN%โœ… Setup complete!%NC% +goto :eof + +:run_backend +cd /d "%PROJECT_ROOT%\backend\cmd" +echo %YELLOW%Starting backend server...%NC% +go run . +goto :eof + +:run_ethernet_view +cd /d "%PROJECT_ROOT%\ethernet-view" +echo %YELLOW%Starting ethernet-view dev server...%NC% +call npm run dev +goto :eof + +:run_control_station +cd /d "%PROJECT_ROOT%\control-station" +echo %YELLOW%Starting control-station dev server...%NC% +call npm run dev +goto :eof + +:run_packet_sender +cd /d "%PROJECT_ROOT%\packet-sender" +echo %YELLOW%Starting packet-sender...%NC% +go run . +goto :eof + +:run_all_parallel +echo %YELLOW%Starting all services in parallel...%NC% +echo %YELLOW%Use Ctrl+C to stop all services%NC% +echo. + +rem Create a temporary batch file to run services in parallel +set TEMP_BATCH=%TEMP%\hyperloop_services.bat + +echo @echo off > "%TEMP_BATCH%" +echo start "Backend" /D "%PROJECT_ROOT%\backend\cmd" cmd /k "go run ." >> "%TEMP_BATCH%" +echo start "Ethernet View" /D "%PROJECT_ROOT%\ethernet-view" cmd /k "npm run dev" >> "%TEMP_BATCH%" +echo start "Control Station" /D "%PROJECT_ROOT%\control-station" cmd /k "npm run dev" >> "%TEMP_BATCH%" +echo start "Packet Sender" /D "%PROJECT_ROOT%\packet-sender" cmd /k "go run ." >> "%TEMP_BATCH%" + +call "%TEMP_BATCH%" +del "%TEMP_BATCH%" + +echo %GREEN%All services started in separate windows%NC% +echo %YELLOW%Close the respective command windows to stop each service%NC% +goto :eof + +:run_tests +echo %YELLOW%Running tests...%NC% + +cd /d "%PROJECT_ROOT%\backend" +echo ๐Ÿงช Running backend tests... +go test -v ./... +if errorlevel 1 exit /b 1 + +rem Add more test commands as needed +echo %GREEN%โœ… All tests passed%NC% +goto :eof + +:build_all +cd /d "%PROJECT_ROOT%" +echo %YELLOW%Building all components...%NC% + +rem Check if make is available (e.g., from MinGW or WSL) +where make >nul 2>&1 +if not errorlevel 1 ( + make all +) else ( + echo %YELLOW%Make not found, building components individually...%NC% + + rem Build backend + echo Building backend... + cd backend + go build -o backend cmd/main.go cmd/config.go cmd/pid.go cmd/trace.go + if errorlevel 1 exit /b 1 + + rem Build common-front + echo Building common-front... + cd ..\common-front + call npm run build + if errorlevel 1 exit /b 1 + + rem Build other frontends + echo Building ethernet-view... + cd ..\ethernet-view + call npm run build + if errorlevel 1 exit /b 1 + + echo Building control-station... + cd ..\control-station + call npm run build + if errorlevel 1 exit /b 1 +) + +echo %GREEN%โœ… Build complete!%NC% +goto :eof + +rem Main script logic +call :print_header +call :check_dependencies + +if "%1"=="" ( + call :print_usage + exit /b 1 +) + +if "%1"=="setup" ( + call :setup_project +) else if "%1"=="backend" ( + call :run_backend +) else if "%1"=="ethernet" ( + call :run_ethernet_view +) else if "%1"=="control" ( + call :run_control_station +) else if "%1"=="packet" ( + call :run_packet_sender +) else if "%1"=="all" ( + call :run_all_parallel +) else if "%1"=="test" ( + call :run_tests +) else if "%1"=="build" ( + call :build_all +) else ( + echo %RED%Unknown command: %1%NC% + call :print_usage + exit /b 1 +) \ No newline at end of file diff --git a/scripts/dev.ps1 b/scripts/dev.ps1 new file mode 100644 index 000000000..40a30d34b --- /dev/null +++ b/scripts/dev.ps1 @@ -0,0 +1,234 @@ +# Development environment setup script for Windows PowerShell +param( + [Parameter(Position=0)] + [string]$Command = "" +) + +# Script setup +$ErrorActionPreference = "Stop" +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$ProjectRoot = Split-Path -Parent $ScriptDir + +# Colors for output +function Write-ColorOutput { + param([string]$Message, [string]$Color = "White") + + switch ($Color) { + "Red" { Write-Host $Message -ForegroundColor Red } + "Green" { Write-Host $Message -ForegroundColor Green } + "Yellow" { Write-Host $Message -ForegroundColor Yellow } + "Cyan" { Write-Host $Message -ForegroundColor Cyan } + default { Write-Host $Message } + } +} + +function Print-Header { + Write-Host "" + Write-ColorOutput "๐Ÿš„ Hyperloop H10 Development Environment" "Green" + Write-ColorOutput "=======================================" "Green" + Write-ColorOutput "OS: Windows (PowerShell)" "Yellow" + Write-Host "" +} + +function Print-Usage { + Write-Host "Usage: .\dev.ps1 [command]" + Write-Host "" + Write-Host "Commands:" + Write-Host " setup - Install all dependencies" + Write-Host " backend - Run backend server" + Write-Host " ethernet - Run ethernet-view dev server" + Write-Host " control - Run control-station dev server" + Write-Host " packet - Run packet-sender" + Write-Host " all - Run all services in parallel" + Write-Host " test - Run all tests" + Write-Host " build - Build all components" + Write-Host "" +} + +function Check-Dependencies { + Write-ColorOutput "Checking dependencies..." "Yellow" + + $missing = @() + + if (-not (Get-Command "go" -ErrorAction SilentlyContinue)) { + $missing += "go" + } + + if (-not (Get-Command "node" -ErrorAction SilentlyContinue)) { + $missing += "node" + } + + if (-not (Get-Command "npm" -ErrorAction SilentlyContinue)) { + $missing += "npm" + } + + if ($missing.Count -gt 0) { + Write-ColorOutput "Error: Missing required dependencies: $($missing -join ', ')" "Red" + Write-Host "Please install them before continuing." + exit 1 + } + + Write-ColorOutput "โœ… All dependencies found" "Green" +} + +function Setup-Project { + Write-ColorOutput "Setting up project dependencies..." "Yellow" + + Set-Location $ProjectRoot + + # Build common-front first + Write-Host "๐Ÿ“ฆ Building common-front..." + Set-Location "common-front" + npm install + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + npm run build + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Install ethernet-view dependencies + Write-Host "๐Ÿ“ฆ Installing ethernet-view dependencies..." + Set-Location "..\ethernet-view" + npm install + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Install control-station dependencies + Write-Host "๐Ÿ“ฆ Installing control-station dependencies..." + Set-Location "..\control-station" + npm install + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Download Go dependencies + Write-Host "๐Ÿ“ฆ Downloading Go dependencies..." + Set-Location "..\backend" + go mod download + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + Set-Location "..\packet-sender" + go mod download + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + Write-ColorOutput "โœ… Setup complete!" "Green" +} + +function Run-Backend { + Set-Location "$ProjectRoot\backend\cmd" + Write-ColorOutput "Starting backend server..." "Yellow" + go run . +} + +function Run-EthernetView { + Set-Location "$ProjectRoot\ethernet-view" + Write-ColorOutput "Starting ethernet-view dev server..." "Yellow" + npm run dev +} + +function Run-ControlStation { + Set-Location "$ProjectRoot\control-station" + Write-ColorOutput "Starting control-station dev server..." "Yellow" + npm run dev +} + +function Run-PacketSender { + Set-Location "$ProjectRoot\packet-sender" + Write-ColorOutput "Starting packet-sender..." "Yellow" + go run . +} + +function Run-AllParallel { + Write-ColorOutput "Starting all services in parallel..." "Yellow" + Write-ColorOutput "Each service will open in a new PowerShell window" "Cyan" + Write-ColorOutput "Close the respective windows to stop each service" "Cyan" + Write-Host "" + + # Start each service in a new PowerShell window + Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$ProjectRoot\backend\cmd'; Write-Host 'Backend Server' -ForegroundColor Green; go run ." + Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$ProjectRoot\ethernet-view'; Write-Host 'Ethernet View' -ForegroundColor Green; npm run dev" + Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$ProjectRoot\control-station'; Write-Host 'Control Station' -ForegroundColor Green; npm run dev" + Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$ProjectRoot\packet-sender'; Write-Host 'Packet Sender' -ForegroundColor Green; go run ." + + Write-ColorOutput "โœ… All services started in separate windows" "Green" +} + +function Run-Tests { + Write-ColorOutput "Running tests..." "Yellow" + + Set-Location "$ProjectRoot\backend" + Write-Host "๐Ÿงช Running backend tests..." + go test -v ./... + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Add more test commands as needed + Write-ColorOutput "โœ… All tests passed" "Green" +} + +function Build-All { + Set-Location $ProjectRoot + Write-ColorOutput "Building all components..." "Yellow" + + # Check if make is available (e.g., from MinGW or WSL) + if (Get-Command "make" -ErrorAction SilentlyContinue) { + make all + } else { + Write-ColorOutput "Make not found, building components individually..." "Yellow" + + # Build backend + Write-Host "Building backend..." + Set-Location "backend" + go build -o backend cmd/main.go cmd/config.go cmd/pid.go cmd/trace.go + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Build common-front + Write-Host "Building common-front..." + Set-Location "..\common-front" + npm run build + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + # Build other frontends + Write-Host "Building ethernet-view..." + Set-Location "..\ethernet-view" + npm run build + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + Write-Host "Building control-station..." + Set-Location "..\control-station" + npm run build + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + + Write-ColorOutput "โœ… Build complete!" "Green" +} + +# Main script logic +Print-Header +Check-Dependencies + +switch ($Command) { + "setup" { + Setup-Project + } + "backend" { + Run-Backend + } + "ethernet" { + Run-EthernetView + } + "control" { + Run-ControlStation + } + "packet" { + Run-PacketSender + } + "all" { + Run-AllParallel + } + "test" { + Run-Tests + } + "build" { + Build-All + } + default { + Write-ColorOutput "Unknown command: $Command" "Red" + Print-Usage + exit 1 + } +} \ No newline at end of file From 23c97028eb038f6dbf6fdc108df386da44c36909 Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Thu, 5 Jun 2025 21:59:10 +0200 Subject: [PATCH 3/5] add unified cross-platform dev script --- scripts/dev-unified.sh | 378 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100755 scripts/dev-unified.sh diff --git a/scripts/dev-unified.sh b/scripts/dev-unified.sh new file mode 100755 index 000000000..1f1fc87f3 --- /dev/null +++ b/scripts/dev-unified.sh @@ -0,0 +1,378 @@ +#!/bin/bash +# Unified cross-platform development script +# Works on Unix/Linux/macOS and Windows (via Git Bash/WSL/MSYS2) + +set -e + +# Get script directory and project root +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + +# Enhanced OS detection +detect_os() { + local os="unknown" + local is_wsl=false + local shell_env="unknown" + + # Detect operating system + case "$(uname -s)" in + Linux*) + if [[ -n "${WSL_DISTRO_NAME:-}" ]] || [[ "$(uname -r)" == *microsoft* ]]; then + os="wsl" + is_wsl=true + else + os="linux" + fi + ;; + Darwin*) os="macos";; + CYGWIN*) os="windows-cygwin";; + MINGW*) os="windows-mingw";; + MSYS*) os="windows-msys";; + *) os="unknown";; + esac + + # Detect shell environment + if [[ -n "${BASH_VERSION:-}" ]]; then + shell_env="bash" + elif [[ -n "${ZSH_VERSION:-}" ]]; then + shell_env="zsh" + else + shell_env="sh" + fi + + echo "$os|$is_wsl|$shell_env" +} + +# Parse OS detection +OS_INFO=$(detect_os) +OS=$(echo "$OS_INFO" | cut -d'|' -f1) +IS_WSL=$(echo "$OS_INFO" | cut -d'|' -f2) +SHELL_ENV=$(echo "$OS_INFO" | cut -d'|' -f3) + +# Determine if we're on Windows-like environment +case "$OS" in + windows-*|wsl) IS_WINDOWS_LIKE=true;; + *) IS_WINDOWS_LIKE=false;; +esac + +# Colors for output (with Windows compatibility) +if [[ "$IS_WINDOWS_LIKE" == "true" ]] && [[ "$OS" != "wsl" ]]; then + # Limited color support on Windows + RED="" + GREEN="" + YELLOW="" + NC="" +else + RED='\033[0;31m' + GREEN='\033[0;32m' + YELLOW='\033[1;33m' + NC='\033[0m' +fi + +print_header() { + echo -e "${GREEN}๐Ÿš„ Hyperloop H10 Development Environment${NC}" + echo -e "${GREEN}=======================================${NC}" + echo -e "${YELLOW}OS: $OS${NC}" + echo -e "${YELLOW}Shell: $SHELL_ENV${NC}" + echo -e "${YELLOW}WSL: $IS_WSL${NC}" + echo "" +} + +print_usage() { + echo "Usage: $0 [command]" + echo "" + echo "Commands:" + echo " setup - Install all dependencies" + echo " backend - Run backend server" + echo " ethernet - Run ethernet-view dev server" + echo " control - Run control-station dev server" + echo " packet - Run packet-sender" + echo " all - Run all services" + echo " test - Run all tests" + echo " build - Build all components" + echo "" + echo "Platform Notes:" + if [[ "$IS_WINDOWS_LIKE" == "true" ]]; then + echo " - Windows detected: Services will run in parallel processes" + echo " - Use Ctrl+C to stop all services when running 'all' command" + else + echo " - Unix-like system: 'all' command uses tmux if available" + echo " - Install tmux for better multi-service management" + fi + echo "" +} + +check_dependencies() { + local missing=() + + command -v go >/dev/null 2>&1 || missing+=("go") + command -v node >/dev/null 2>&1 || missing+=("node") + command -v npm >/dev/null 2>&1 || missing+=("npm") + + if [ ${#missing[@]} -ne 0 ]; then + echo -e "${RED}Error: Missing required dependencies: ${missing[*]}${NC}" + echo "Please install them before continuing." + echo "" + echo "Installation guides:" + echo " Go: https://golang.org/doc/install" + echo " Node.js: https://nodejs.org/" + exit 1 + fi + + echo -e "${GREEN}โœ… All dependencies found${NC}" +} + +# Convert Windows paths if needed +normalize_path() { + local path="$1" + if [[ "$IS_WINDOWS_LIKE" == "true" ]] && [[ "$OS" != "wsl" ]]; then + echo "$path" | sed 's|/|\\|g' + else + echo "$path" + fi +} + +# Cross-platform directory change +safe_cd() { + local target_dir="$1" + local normalized_dir + normalized_dir=$(normalize_path "$target_dir") + + if ! cd "$normalized_dir" 2>/dev/null; then + echo -e "${RED}Error: Cannot change to directory: $normalized_dir${NC}" + exit 1 + fi +} + +setup_project() { + echo -e "${YELLOW}Setting up project dependencies...${NC}" + + safe_cd "$PROJECT_ROOT" + + # Build common-front first + echo "๐Ÿ“ฆ Building common-front..." + safe_cd "$PROJECT_ROOT/common-front" + npm install + npm run build + + # Install ethernet-view dependencies + echo "๐Ÿ“ฆ Installing ethernet-view dependencies..." + safe_cd "$PROJECT_ROOT/ethernet-view" + npm install + + # Install control-station dependencies + echo "๐Ÿ“ฆ Installing control-station dependencies..." + safe_cd "$PROJECT_ROOT/control-station" + npm install + + # Download Go dependencies + echo "๐Ÿ“ฆ Downloading Go dependencies..." + safe_cd "$PROJECT_ROOT/backend" + go mod download + + safe_cd "$PROJECT_ROOT/packet-sender" + go mod download + + echo -e "${GREEN}โœ… Setup complete!${NC}" +} + +run_backend() { + safe_cd "$PROJECT_ROOT/backend/cmd" + echo -e "${YELLOW}Starting backend server...${NC}" + go run . +} + +run_ethernet_view() { + safe_cd "$PROJECT_ROOT/ethernet-view" + echo -e "${YELLOW}Starting ethernet-view dev server...${NC}" + npm run dev +} + +run_control_station() { + safe_cd "$PROJECT_ROOT/control-station" + echo -e "${YELLOW}Starting control-station dev server...${NC}" + npm run dev +} + +run_packet_sender() { + safe_cd "$PROJECT_ROOT/packet-sender" + echo -e "${YELLOW}Starting packet-sender...${NC}" + go run . +} + +run_all_services() { + if [[ "$IS_WINDOWS_LIKE" == "true" ]] && [[ "$OS" != "wsl" ]]; then + echo -e "${YELLOW}Running all services in parallel (Windows mode)...${NC}" + echo -e "${YELLOW}Use Ctrl+C to stop all services${NC}" + echo "" + + # Start all services in background + (safe_cd "$PROJECT_ROOT/backend/cmd" && go run .) & + PID_BACKEND=$! + + (safe_cd "$PROJECT_ROOT/ethernet-view" && npm run dev) & + PID_ETHERNET=$! + + (safe_cd "$PROJECT_ROOT/control-station" && npm run dev) & + PID_CONTROL=$! + + (safe_cd "$PROJECT_ROOT/packet-sender" && go run .) & + PID_PACKET=$! + + echo -e "${GREEN}All services started. PIDs: Backend=$PID_BACKEND, Ethernet=$PID_ETHERNET, Control=$PID_CONTROL, Packet=$PID_PACKET${NC}" + + # Function to cleanup on exit + cleanup() { + echo -e "${YELLOW}Stopping all services...${NC}" + kill $PID_BACKEND $PID_ETHERNET $PID_CONTROL $PID_PACKET 2>/dev/null || true + exit + } + + # Set trap for cleanup + trap cleanup SIGINT SIGTERM + + # Wait for any process to exit + wait + + else + # Unix-like system - prefer tmux if available + if command -v tmux >/dev/null 2>&1; then + run_all_tmux + else + echo -e "${YELLOW}tmux not found. Running services in parallel...${NC}" + echo -e "${YELLOW}Use Ctrl+C to stop all services${NC}" + echo "" + + # Fallback to background processes + (safe_cd "$PROJECT_ROOT/backend/cmd" && go run .) & + PID_BACKEND=$! + + (safe_cd "$PROJECT_ROOT/ethernet-view" && npm run dev) & + PID_ETHERNET=$! + + (safe_cd "$PROJECT_ROOT/control-station" && npm run dev) & + PID_CONTROL=$! + + (safe_cd "$PROJECT_ROOT/packet-sender" && go run .) & + PID_PACKET=$! + + echo -e "${GREEN}All services started. PIDs: Backend=$PID_BACKEND, Ethernet=$PID_ETHERNET, Control=$PID_CONTROL, Packet=$PID_PACKET${NC}" + echo -e "${YELLOW}Tip: Install tmux for better session management${NC}" + + # Function to cleanup on exit + cleanup() { + echo -e "${YELLOW}Stopping all services...${NC}" + kill $PID_BACKEND $PID_ETHERNET $PID_CONTROL $PID_PACKET 2>/dev/null || true + exit + } + + # Set trap for cleanup + trap cleanup SIGINT SIGTERM + + # Wait for any process to exit + wait + fi + fi +} + +run_all_tmux() { + SESSION="hyperloop-dev" + + # Kill existing session if it exists + tmux kill-session -t $SESSION 2>/dev/null || true + + # Create new session with backend + tmux new-session -d -s $SESSION -n backend "cd '$PROJECT_ROOT/backend/cmd' && go run ." + + # Create windows for other services + tmux new-window -t $SESSION -n ethernet-view "cd '$PROJECT_ROOT/ethernet-view' && npm run dev" + tmux new-window -t $SESSION -n control-station "cd '$PROJECT_ROOT/control-station' && npm run dev" + tmux new-window -t $SESSION -n packet-sender "cd '$PROJECT_ROOT/packet-sender' && go run ." + + # Attach to session + echo -e "${GREEN}Starting all services in tmux session '$SESSION'${NC}" + echo -e "${YELLOW}Use 'tmux attach -t $SESSION' to reconnect${NC}" + tmux attach-session -t $SESSION +} + +run_tests() { + echo -e "${YELLOW}Running tests...${NC}" + + safe_cd "$PROJECT_ROOT/backend" + echo "๐Ÿงช Running backend tests..." + go test -v ./... + + echo -e "${GREEN}โœ… All tests completed${NC}" +} + +build_all() { + safe_cd "$PROJECT_ROOT" + echo -e "${YELLOW}Building all components...${NC}" + + # Check if make is available + if command -v make >/dev/null 2>&1; then + make all + else + echo -e "${YELLOW}Make not found, building components individually...${NC}" + + # Build backend + echo "Building backend..." + safe_cd "$PROJECT_ROOT/backend" + go build -o backend cmd/main.go cmd/config.go cmd/pid.go cmd/trace.go + + # Build common-front + echo "Building common-front..." + safe_cd "$PROJECT_ROOT/common-front" + npm run build + + # Build other frontends + echo "Building ethernet-view..." + safe_cd "$PROJECT_ROOT/ethernet-view" + npm run build + + echo "Building control-station..." + safe_cd "$PROJECT_ROOT/control-station" + npm run build + fi + + echo -e "${GREEN}โœ… Build complete!${NC}" +} + +# Main script logic +print_header +check_dependencies + +case "${1:-}" in + setup) + setup_project + ;; + backend) + run_backend + ;; + ethernet) + run_ethernet_view + ;; + control) + run_control_station + ;; + packet) + run_packet_sender + ;; + all) + run_all_services + ;; + test) + run_tests + ;; + build) + build_all + ;; + "") + print_usage + ;; + *) + echo -e "${RED}Unknown command: $1${NC}" + print_usage + exit 1 + ;; +esac \ No newline at end of file From 87016b274e0df0465b9d5160b379e49488b3e382 Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Thu, 5 Jun 2025 21:59:18 +0200 Subject: [PATCH 4/5] add scripts documentation --- scripts/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scripts/README.md diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 000000000..ce76734d5 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,42 @@ +# Development Scripts + +This directory contains cross-platform development scripts for the Hyperloop H10 project. + +## Quick Reference + +```bash +# Unix/Linux/macOS +./scripts/dev.sh setup +./scripts/dev.sh all + +# Windows PowerShell +.\scripts\dev.ps1 setup +.\scripts\dev.ps1 all + +# Windows Command Prompt +scripts\dev.cmd setup +scripts\dev.cmd all +``` + +## Complete Documentation + +๐Ÿ“š **Full documentation has moved to: [docs/development/scripts.md](../docs/development/scripts.md)** + +The complete documentation includes: +- Detailed usage instructions for all platforms +- Platform-specific notes and troubleshooting +- Advanced configuration options +- CI/CD integration details + +## Available Scripts + +- **`dev.sh`** - Unix/Linux/macOS development script +- **`dev.ps1`** - Windows PowerShell script (recommended) +- **`dev.cmd`** - Windows Command Prompt script +- **`dev-unified.sh`** - Universal cross-platform script + +## Need Help? + +- Check the [full documentation](../docs/development/scripts.md) +- Read the [getting started guide](../docs/guides/getting-started.md) +- View [troubleshooting docs](../docs/troubleshooting/) \ No newline at end of file From ead344541db341b9ab918781a61dbaa3d7adce92 Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Thu, 5 Jun 2025 21:59:32 +0200 Subject: [PATCH 5/5] add CI workflow for development scripts --- .github/workflows/test-dev-scripts.yaml | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/test-dev-scripts.yaml diff --git a/.github/workflows/test-dev-scripts.yaml b/.github/workflows/test-dev-scripts.yaml new file mode 100644 index 000000000..d74a43168 --- /dev/null +++ b/.github/workflows/test-dev-scripts.yaml @@ -0,0 +1,82 @@ +name: Test Development Scripts + +on: + pull_request: + paths: + - scripts/** + workflow_dispatch: + +jobs: + test-dev-scripts: + name: Test Development Scripts + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + name: linux + shell: bash + script: ./scripts/dev.sh + + - os: windows-latest + name: windows-powershell + shell: pwsh + script: .\scripts\dev.ps1 + + - os: windows-latest + name: windows-cmd + shell: cmd + script: scripts\dev.cmd + + - os: macos-latest + name: macos + shell: bash + script: ./scripts/dev.sh + + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install tmux (Linux/macOS) + if: matrix.os != 'windows-latest' + run: | + if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then + sudo apt-get update && sudo apt-get install -y tmux + elif [ "${{ matrix.os }}" = "macos-latest" ]; then + brew install tmux + fi + shell: bash + + - name: Make script executable (Unix) + if: matrix.os != 'windows-latest' + run: chmod +x scripts/dev.sh + shell: bash + + - name: Test script help/usage + run: ${{ matrix.script }} + shell: ${{ matrix.shell }} + continue-on-error: true + + - name: Test dependency check + run: ${{ matrix.script }} setup + shell: ${{ matrix.shell }} + + - name: Test build command + run: ${{ matrix.script }} build + shell: ${{ matrix.shell }} + continue-on-error: true + + - name: Test backend build (quick test) + run: ${{ matrix.script }} test + shell: ${{ matrix.shell }} + continue-on-error: true \ No newline at end of file