-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.bat
More file actions
106 lines (93 loc) · 3.4 KB
/
launch.bat
File metadata and controls
106 lines (93 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@echo off
:: =============================================================================
:: 1-CLICK LAUNCHER for News App (Python + React)
:: - Byron's Modular Workflow (Dec 2025)
:: - Checks/creates .venv, installs deps, launches backend + frontend
:: =============================================================================
setlocal enabledelayedexpansion
echo [+] Initializing News App Launcher...
echo [+] Project root: %~dp0
cd /d "%~dp0"
:: === STEP 1: Python Virtual Environment ===
echo.
echo [*] Checking Python virtual environment (.venv)...
if exist ".venv\Scripts\activate.bat" (
echo [+] .venv found. Activating...
call ".venv\Scripts\activate.bat"
) else (
echo [-] .venv not found. Creating...
python -m venv .venv
if errorlevel 1 (
echo [!] ERROR: Failed to create .venv. Is Python installed?
echo Try: python --version
pause
exit /b 1
)
call ".venv\Scripts\activate.bat"
echo [+] .venv created and activated.
)
:: === STEP 2: Install/Update Python Dependencies ===
echo.
echo [*] Checking Python dependencies...
pip install -r requirements.txt --upgrade
if errorlevel 1 (
echo [!] ERROR: Failed to install Python requirements.
pause
exit /b 1
)
echo [+] Python dependencies ready.
:: === STEP 3: Launch Backend (FastAPI) in Background ===
echo.
echo [*] Starting backend (FastAPI) on http://127.0.0.1:8000 ...
start "FastAPI Backend" cmd /c "python main.py"
timeout /t 3 /nobreak >nul
:: Verify backend is responsive
echo [*] Verifying backend health...
powershell -Command ^
"$ErrorActionPreference='Stop';" ^
"try {" ^
" $res = Invoke-WebRequest -Uri 'http://127.0.0.1:8000/api/news' -TimeoutSec 5;" ^
" if ($res.StatusCode -eq 200) { exit 0 } else { exit 1 }" ^
"} catch { exit 1 }"
if errorlevel 1 (
echo [!] WARNING: Backend may not be ready. Check console window.
echo (It may still start — proceeding...)
) else (
echo [+] Backend is healthy.
)
:: === STEP 4: Node.js & Frontend ===
cd /d "%~dp0\frontend"
echo.
echo [*] Checking Node.js installation...
node --version >nul 2>&1
if errorlevel 1 (
echo [!] ERROR: Node.js not found. Install from https://nodejs.org
pause
exit /b 1
)
echo [+] Node.js detected.
echo [*] Installing/updating frontend dependencies...
npm install --no-fund --no-audit --loglevel=error
if errorlevel 1 (
echo [!] ERROR: Failed to install Node.js dependencies.
pause
exit /b 1
)
echo [+] Frontend dependencies ready.
:: === STEP 5: Launch Frontend ===
echo.
echo [+] Launching React frontend on http://127.0.0.1:3000 ...
echo.
echo ┌──────────────────────────────────────────────────────┐
echo │ ✅ LAUNCH COMPLETE! │
echo │ • Backend: http://127.0.0.1:8000/docs │
echo │ • Frontend: http://127.0.0.1:3000 │
echo │ • To stop: Close both console windows. │
echo └──────────────────────────────────────────────────────┘
echo.
:: Open browser (optional — comment out if undesired)
start http://127.0.0.1:3000
:: Start frontend in current window (keeps launcher alive)
npm run dev
:: Cleanup (won’t run unless script is killed)
endlocal