From 9c85e08839701202eb724e47f3d2cfcc0c0e8a09 Mon Sep 17 00:00:00 2001 From: anoracleofra-code Date: Sun, 8 Mar 2026 14:55:11 -0600 Subject: [PATCH] fix: integrate AI cross-platform start scripts Former-commit-id: 2054b6036dbdc9586272f324c233640183b75379 --- frontend/package.json | 2 +- start-backend.js | 20 ++++++++++++++++++++ start.sh | 40 +++++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 start-backend.js diff --git a/frontend/package.json b/frontend/package.json index dc8ac53..cc34776 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "concurrently \"npm run dev:frontend\" \"npm run dev:backend\"", "dev:frontend": "next dev", - "dev:backend": "cd ../backend && python -m uvicorn main:app --reload", + "dev:backend": "node ../start-backend.js", "build": "next build", "start": "next start", "lint": "eslint" diff --git a/start-backend.js b/start-backend.js new file mode 100644 index 0000000..2b19e1d --- /dev/null +++ b/start-backend.js @@ -0,0 +1,20 @@ +const { execSync } = require("child_process"); +const path = require("path"); +const fs = require("fs"); + +const backendDir = path.resolve(__dirname, "backend"); +const venvBin = process.platform === "win32" + ? path.join(backendDir, "venv", "Scripts", "python.exe") + : path.join(backendDir, "venv", "bin", "python3"); + +if (!fs.existsSync(venvBin)) { + console.error(`[!] Python venv not found at: ${venvBin}`); + console.error("[!] Run start.sh (Mac/Linux) or start.bat (Windows) first to create the venv."); + process.exit(1); +} + +console.log(`[*] Starting backend with: ${venvBin}`); +execSync(`"${venvBin}" -m uvicorn main:app --reload`, { + cwd: backendDir, + stdio: "inherit", +}); diff --git a/start.sh b/start.sh index 2684942..0dbbcdf 100644 --- a/start.sh +++ b/start.sh @@ -10,31 +10,38 @@ if ! command -v npm &> /dev/null; then exit 1 fi -# Check for Python -if ! command -v python3 &> /dev/null; then +# Check for Python 3 +PYTHON_CMD="" +if command -v python3 &> /dev/null; then + PYTHON_CMD="python3" +elif command -v python &> /dev/null; then + PYTHON_CMD="python" +else echo "[!] ERROR: python3 is not installed. Please install Python 3.10+ (https://python.org/)" exit 1 fi +echo "[*] Using Python: $PYTHON_CMD ($($PYTHON_CMD --version 2>&1))" + +# Get the directory where this script lives (handles running from any location) +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + echo "[*] Setting up Backend Environment..." -cd backend +cd "$SCRIPT_DIR/backend" if [ ! -d "venv" ]; then echo "[*] Creating Python Virtual Environment..." - python3 -m venv venv + $PYTHON_CMD -m venv venv fi echo "[*] Installing Backend dependencies..." -if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then - # In case someone runs this in Git Bash on Windows - source venv/Scripts/activate -else - source venv/bin/activate -fi -pip install -r requirements.txt -cd .. +source venv/bin/activate +pip install -q -r requirements.txt +deactivate + +cd "$SCRIPT_DIR" echo "[*] Setting up Frontend Environment..." -cd frontend +cd "$SCRIPT_DIR/frontend" if [ ! -d "node_modules" ]; then echo "[*] Installing Frontend dependencies..." npm install @@ -42,11 +49,10 @@ fi echo "" echo "=======================================================" -echo " 🚀 Starting Services... " -echo " Dashboard will be available at: http://localhost:3000" -echo " Keep this window open! Note: Initial load takes ~10s " +echo " Starting Services... " +echo " Dashboard will be available at: http://localhost:3000 " +echo " Keep this window open! Initial load takes ~10s " echo "=======================================================" echo "" -# Start both services (npm run dev automatically calls the python backend on Mac/Linux if scripts are configured cross-platform) npm run dev