-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.bat
More file actions
402 lines (333 loc) · 11 KB
/
start.bat
File metadata and controls
402 lines (333 loc) · 11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@echo off
setlocal enabledelayedexpansion
REM 🏢⚡ Energy Optimizer Pro - Windows Quick Start Script
REM ======================================================
title Energy Optimizer Pro - Setup and Launch
REM Colors for Windows (using PowerShell for colored output)
set "ESC="
echo.
echo ================================================================
echo 🏢⚡ ENERGY OPTIMIZER PRO - WINDOWS QUICK START
echo ================================================================
echo.
REM Function to print colored messages
:print_message
if "%1"=="info" (
powershell -Command "Write-Host 'ℹ️ %~2' -ForegroundColor Cyan"
) else if "%1"=="success" (
powershell -Command "Write-Host '✅ %~2' -ForegroundColor Green"
) else if "%1"=="warning" (
powershell -Command "Write-Host '⚠️ %~2' -ForegroundColor Yellow"
) else if "%1"=="error" (
powershell -Command "Write-Host '❌ %~2' -ForegroundColor Red"
) else if "%1"=="process" (
powershell -Command "Write-Host '⚙️ %~2' -ForegroundColor Blue"
)
goto :eof
REM Check if we're in the right directory
if not exist "package.json" (
call :print_message "error" "Please run this script from the project root directory"
pause
exit /b 1
)
REM Parse command line arguments
set "COMMAND=%1"
if "%COMMAND%"=="" set "COMMAND=help"
REM Main command router
if "%COMMAND%"=="install" goto :install
if "%COMMAND%"=="start" goto :start
if "%COMMAND%"=="stop" goto :stop
if "%COMMAND%"=="status" goto :status
if "%COMMAND%"=="logs" goto :logs
if "%COMMAND%"=="clean" goto :clean
if "%COMMAND%"=="test" goto :test
if "%COMMAND%"=="help" goto :help
goto :help
:install
call :print_message "info" "Installing Energy Optimizer Pro..."
call :check_requirements
if errorlevel 1 exit /b 1
call :setup_environment
call :install_dependencies
call :setup_database
call :print_message "success" "Installation completed successfully!"
call :print_message "info" "Run 'start.bat start' to launch the application"
goto :end
:start
call :print_message "process" "Starting Energy Optimizer Pro..."
echo.
echo Choose deployment method:
echo 1) Docker Compose (Recommended)
echo 2) Local Development
echo 3) Production Docker
echo.
set /p "DEPLOY_CHOICE=Enter your choice (1-3): "
if "%DEPLOY_CHOICE%"=="1" goto :start_docker
if "%DEPLOY_CHOICE%"=="2" goto :start_local
if "%DEPLOY_CHOICE%"=="3" goto :start_production
call :print_message "error" "Invalid choice. Exiting."
goto :end
:start_docker
call :print_message "process" "Starting with Docker Compose..."
docker-compose up --build
goto :end
:start_local
call :print_message "process" "Starting local development servers..."
REM Start backend in new window
call :print_message "process" "Starting FastAPI backend on port 8000..."
start "Energy Optimizer - Backend" cmd /k "cd backend && venv\Scripts\activate && python main.py"
REM Wait for backend to start
timeout /t 5 /nobreak > nul
REM Start frontend in new window
call :print_message "process" "Starting Next.js frontend on port 3000..."
start "Energy Optimizer - Frontend" cmd /k "cd frontend && npm run dev"
call :print_message "success" "Services started successfully!"
call :print_message "info" "Frontend: http://localhost:3000"
call :print_message "info" "Backend API: http://localhost:8000"
call :print_message "info" "API Docs: http://localhost:8000/docs"
echo.
call :print_message "info" "Press any key to stop all services..."
pause > nul
REM Stop services
taskkill /f /im "python.exe" 2>nul
taskkill /f /im "node.exe" 2>nul
call :print_message "success" "Services stopped"
goto :end
:start_production
call :print_message "process" "Starting production deployment..."
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --build
goto :end
:stop
call :print_message "process" "Stopping all services..."
REM Stop Docker services
docker-compose down 2>nul
REM Stop local processes
taskkill /f /im "python.exe" 2>nul
taskkill /f /im "node.exe" 2>nul
call :print_message "success" "All services stopped"
goto :end
:status
call :print_message "process" "Checking service status..."
REM Check if ports are in use
netstat -an | find ":3000" > nul
if !errorlevel! == 0 (
call :print_message "success" "Frontend is running on port 3000"
) else (
call :print_message "warning" "Frontend is not running"
)
netstat -an | find ":8000" > nul
if !errorlevel! == 0 (
call :print_message "success" "Backend is running on port 8000"
) else (
call :print_message "warning" "Backend is not running"
)
REM Check Docker services
docker-compose ps 2>nul | find "Up" > nul
if !errorlevel! == 0 (
call :print_message "success" "Docker services are running"
docker-compose ps
) else (
call :print_message "warning" "Docker services are not running"
)
goto :end
:logs
call :print_message "info" "Showing application logs..."
REM Check if Docker is running
docker-compose ps 2>nul | find "Up" > nul
if !errorlevel! == 0 (
call :print_message "info" "Showing Docker Compose logs..."
docker-compose logs -f
) else (
call :print_message "info" "Showing local logs..."
if exist "logs\*.log" (
type logs\*.log
) else (
call :print_message "warning" "No log files found"
)
)
goto :end
:test
call :print_message "process" "Running tests..."
REM Frontend tests
call :print_message "process" "Running frontend tests..."
cd frontend
call npm run test:ci
cd ..
REM Backend tests
call :print_message "process" "Running backend tests..."
cd backend
call venv\Scripts\activate.bat && python -m pytest
cd ..
call :print_message "success" "All tests completed"
goto :end
:clean
call :print_message "process" "Cleaning up..."
REM Stop services first
call :stop
REM Clean Docker
docker system prune -f 2>nul
REM Clean temporary files
if exist "frontend\.next" rmdir /s /q "frontend\.next"
if exist "backend\__pycache__" rmdir /s /q "backend\__pycache__"
del /q logs\*.log 2>nul
call :print_message "success" "Cleanup completed"
goto :end
:check_requirements
call :print_message "info" "Checking system requirements..."
REM Check Node.js
node --version >nul 2>&1
if errorlevel 1 (
call :print_message "error" "Node.js not found. Please install Node.js 18+ from https://nodejs.org"
exit /b 1
) else (
for /f "tokens=*" %%i in ('node --version') do (
call :print_message "success" "Node.js found: %%i"
)
)
REM Check npm
npm --version >nul 2>&1
if errorlevel 1 (
call :print_message "error" "npm not found. Please install npm"
exit /b 1
) else (
for /f "tokens=*" %%i in ('npm --version') do (
call :print_message "success" "npm found: v%%i"
)
)
REM Check Python
python --version >nul 2>&1
if errorlevel 1 (
call :print_message "error" "Python not found. Please install Python 3.11+ from https://python.org"
exit /b 1
) else (
for /f "tokens=*" %%i in ('python --version') do (
call :print_message "success" "Python found: %%i"
)
)
REM Check pip
pip --version >nul 2>&1
if errorlevel 1 (
call :print_message "error" "pip not found. Please install pip"
exit /b 1
) else (
for /f "tokens=*" %%i in ('pip --version') do (
call :print_message "success" "pip found: %%i"
)
)
REM Check Docker (optional)
docker --version >nul 2>&1
if errorlevel 1 (
call :print_message "warning" "Docker not found. Docker deployment will be unavailable"
) else (
for /f "tokens=*" %%i in ('docker --version') do (
call :print_message "success" "Docker found: %%i"
)
)
exit /b 0
:setup_environment
call :print_message "process" "Setting up environment..."
REM Create environment files
if not exist "frontend\.env.local" (
copy "frontend\.env.example" "frontend\.env.local" >nul
call :print_message "success" "Frontend .env.local created"
)
if not exist "backend\.env" (
copy "backend\.env.example" "backend\.env" >nul
call :print_message "success" "Backend .env created"
)
REM Create required directories
if not exist "logs" mkdir logs
if not exist "data" mkdir data
if not exist "models" mkdir models
if not exist "uploads" mkdir uploads
if not exist "backups" mkdir backups
call :print_message "success" "Required directories created"
goto :eof
:install_dependencies
call :print_message "process" "Installing dependencies..."
REM Install frontend dependencies
call :print_message "process" "Installing frontend dependencies..."
cd frontend
call npm install
if errorlevel 1 (
call :print_message "error" "Frontend dependency installation failed"
cd ..
exit /b 1
)
cd ..
call :print_message "success" "Frontend dependencies installed"
REM Install backend dependencies
call :print_message "process" "Installing backend dependencies..."
cd backend
REM Create virtual environment
if not exist "venv" (
call :print_message "process" "Creating Python virtual environment..."
python -m venv venv
call :print_message "success" "Virtual environment created"
)
REM Activate virtual environment and install dependencies
call venv\Scripts\activate.bat
python -m pip install --upgrade pip
pip install -r requirements.txt
if errorlevel 1 (
call :print_message "error" "Backend dependency installation failed"
cd ..
exit /b 1
)
cd ..
call :print_message "success" "Backend dependencies installed"
goto :eof
:setup_database
call :print_message "process" "Setting up database..."
REM Check if Docker is available
docker --version >nul 2>&1
if errorlevel 1 (
call :print_message "warning" "Docker not available. Please setup PostgreSQL manually:"
echo 1. Install PostgreSQL 15+
echo 2. Create database 'energy_optimizer'
echo 3. Update DATABASE_URL in backend\.env
echo 4. Run: cd backend ^&^& venv\Scripts\activate ^&^& python -m alembic upgrade head
) else (
call :print_message "process" "Starting PostgreSQL with Docker..."
docker-compose up -d postgres redis
REM Wait for database
call :print_message "process" "Waiting for database to be ready..."
timeout /t 10 /nobreak > nul
REM Run migrations
call :print_message "process" "Running database migrations..."
cd backend
call venv\Scripts\activate.bat
python -m alembic upgrade head
cd ..
call :print_message "success" "Database setup completed with Docker"
)
goto :eof
:help
echo.
echo Usage: start.bat [OPTION]
echo.
echo Options:
echo install Install dependencies and setup environment
echo start Start the application
echo stop Stop all running services
echo status Check service status
echo logs Show application logs
echo test Run tests
echo clean Clean up temporary files
echo help Show this help message
echo.
echo Examples:
echo start.bat install # Setup everything
echo start.bat start # Start the application
echo start.bat logs # View logs
echo.
goto :end
:end
echo.
call :print_message "info" "Visit the application at: http://localhost:3000"
call :print_message "info" "API documentation: http://localhost:8000/docs"
call :print_message "info" "For help: start.bat help"
echo.
call :print_message "success" "Energy Optimizer Pro is ready! 🏢⚡"
echo.
pause