-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ps1
More file actions
319 lines (274 loc) · 10.7 KB
/
run.ps1
File metadata and controls
319 lines (274 loc) · 10.7 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
# run.ps1 - Script unificado para Atmos
# Uso: .\run.ps1 [comando]
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
function Show-Help {
Write-Host ""
Write-Host "Atmos - Comandos Disponibles" -ForegroundColor Cyan
Write-Host ""
Write-Host "Setup:" -ForegroundColor Yellow
Write-Host " .\run.ps1 setup - Configurar todo (backend + frontend)"
Write-Host ""
Write-Host "Desarrollo:" -ForegroundColor Green
Write-Host " .\run.ps1 backend - Ejecutar servidor backend"
Write-Host " .\run.ps1 frontend - Ejecutar servidor frontend"
Write-Host ""
Write-Host "Base de Datos:" -ForegroundColor Blue
Write-Host " .\run.ps1 migrate - Aplicar migraciones"
Write-Host " .\run.ps1 migrations - Crear migraciones"
Write-Host " .\run.ps1 superuser - Crear superusuario admin"
Write-Host ""
Write-Host "Tests:" -ForegroundColor Magenta
Write-Host " .\run.ps1 test-backend - Ejecutar tests backend"
Write-Host " .\run.ps1 test-frontend - Ejecutar tests frontend (si existen)"
Write-Host ""
Write-Host "Build:" -ForegroundColor DarkYellow
Write-Host " .\run.ps1 build - Build produccion frontend"
Write-Host ""
Write-Host "Utilidades:" -ForegroundColor Gray
Write-Host " .\run.ps1 clean - Limpiar archivos temporales"
Write-Host " .\run.ps1 help - Mostrar esta ayuda"
Write-Host ""
}
function Setup-All {
Write-Host ""
Write-Host "Configurando Atmos..." -ForegroundColor Cyan
Write-Host ""
# Backend
Write-Host "Configurando backend..." -ForegroundColor Yellow
if (!(Test-Path "backend/venv")) {
Write-Host " Creando entorno virtual..." -ForegroundColor Gray
python -m venv backend/venv
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERROR: No se pudo crear entorno virtual" -ForegroundColor Red
Write-Host "Solucion: Asegurate de tener Python 3.10+ instalado" -ForegroundColor Cyan
Write-Host "Verifica con: python --version" -ForegroundColor Cyan
return
}
Write-Host " Entorno virtual creado" -ForegroundColor Green
} else {
Write-Host " Entorno virtual ya existe" -ForegroundColor Green
}
Write-Host " Instalando dependencias..." -ForegroundColor Gray
& backend/venv/Scripts/python.exe -m pip install --quiet --upgrade pip
& backend/venv/Scripts/pip.exe install --quiet -r backend/requirements.txt
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERROR: No se pudieron instalar dependencias" -ForegroundColor Red
Write-Host "Solucion: Revisa el archivo backend/requirements.txt" -ForegroundColor Cyan
return
}
Write-Host " Dependencias instaladas" -ForegroundColor Green
Write-Host " Aplicando migraciones..." -ForegroundColor Gray
& backend/venv/Scripts/python.exe backend/manage.py migrate --no-input 2>&1 | Out-Null
Write-Host " Migraciones aplicadas" -ForegroundColor Green
Write-Host ""
Write-Host "Backend configurado correctamente" -ForegroundColor Green
Write-Host ""
# Frontend
Write-Host "Configurando frontend..." -ForegroundColor Yellow
# Verificar pnpm
$pnpmCheck = Get-Command pnpm -ErrorAction SilentlyContinue
if (!$pnpmCheck) {
Write-Host ""
Write-Host "ERROR: pnpm no esta instalado" -ForegroundColor Red
Write-Host "Solucion: npm install -g pnpm" -ForegroundColor Cyan
return
}
Write-Host " Instalando dependencias..." -ForegroundColor Gray
Set-Location frontend
pnpm install --silent
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERROR: No se pudieron instalar dependencias" -ForegroundColor Red
Write-Host "Solucion: rm -r node_modules; pnpm install" -ForegroundColor Cyan
Set-Location ..
return
}
Set-Location ..
Write-Host " Dependencias instaladas" -ForegroundColor Green
Write-Host ""
Write-Host "Frontend configurado correctamente" -ForegroundColor Green
Write-Host ""
Write-Host "Todo listo!" -ForegroundColor Cyan
Write-Host ""
Write-Host "Proximos pasos:" -ForegroundColor White
Write-Host " 1. Inicia el backend: .\run.ps1 backend" -ForegroundColor Gray
Write-Host " 2. Inicia el frontend: .\run.ps1 frontend (en otra terminal)" -ForegroundColor Gray
Write-Host ""
}
function Start-Backend {
Write-Host ""
Write-Host "Iniciando backend Django..." -ForegroundColor Yellow
Write-Host ""
if (!(Test-Path "backend/venv")) {
Write-Host "ERROR: Entorno virtual no encontrado" -ForegroundColor Red
Write-Host ""
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
Write-Host ""
return
}
if (!(Test-Path "backend/manage.py")) {
Write-Host "ERROR: No se encontro manage.py" -ForegroundColor Red
Write-Host ""
Write-Host "Verifica que estes en la raiz del proyecto" -ForegroundColor Cyan
Write-Host ""
return
}
Write-Host "Backend disponible en: http://127.0.0.1:8000" -ForegroundColor Green
Write-Host "Presiona Ctrl+C para detener" -ForegroundColor Gray
Write-Host ""
& backend/venv/Scripts/python.exe backend/manage.py runserver
}
function Start-Frontend {
Write-Host ""
Write-Host "Iniciando frontend Vite..." -ForegroundColor Green
Write-Host ""
if (!(Test-Path "frontend/node_modules")) {
Write-Host "ERROR: Dependencias no encontradas" -ForegroundColor Red
Write-Host ""
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
Write-Host ""
return
}
Write-Host "Frontend disponible en: http://localhost:5173" -ForegroundColor Green
Write-Host "Presiona Ctrl+C para detener" -ForegroundColor Gray
Write-Host ""
Set-Location frontend
pnpm dev
Set-Location ..
}
function Run-Migrate {
Write-Host ""
Write-Host "Aplicando migraciones..." -ForegroundColor Blue
Write-Host ""
if (!(Test-Path "backend/venv")) {
Write-Host "ERROR: Entorno virtual no encontrado" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
& backend/venv/Scripts/python.exe backend/manage.py migrate
Write-Host ""
Write-Host "Migraciones aplicadas" -ForegroundColor Green
Write-Host ""
}
function Create-Migrations {
Write-Host ""
Write-Host "Creando migraciones..." -ForegroundColor Blue
Write-Host ""
if (!(Test-Path "backend/venv")) {
Write-Host "ERROR: Entorno virtual no encontrado" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
& backend/venv/Scripts/python.exe backend/manage.py makemigrations
Write-Host ""
}
function Create-Superuser {
Write-Host ""
Write-Host "Creando superusuario..." -ForegroundColor Blue
Write-Host ""
if (!(Test-Path "backend/venv")) {
Write-Host "ERROR: Entorno virtual no encontrado" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
& backend/venv/Scripts/python.exe backend/manage.py createsuperuser
}
function Test-Backend {
Write-Host ""
Write-Host "Ejecutando tests backend..." -ForegroundColor Magenta
Write-Host ""
if (!(Test-Path "backend/venv")) {
Write-Host "ERROR: Entorno virtual no encontrado" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
& backend/venv/Scripts/python.exe -m pytest backend/ -v
Write-Host ""
}
function Test-Frontend {
Write-Host ""
Write-Host "Ejecutando tests frontend..." -ForegroundColor Magenta
Write-Host ""
if (!(Test-Path "frontend/node_modules")) {
Write-Host "ERROR: Dependencias no encontradas" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
Set-Location frontend
# Verificar si existe script de test
$packageJson = Get-Content package.json | ConvertFrom-Json
if ($packageJson.scripts.test) {
pnpm test
} else {
Write-Host "AVISO: No hay tests configurados todavia" -ForegroundColor Yellow
Write-Host "Anade un script 'test' en package.json" -ForegroundColor Cyan
}
Set-Location ..
Write-Host ""
}
function Build-Frontend {
Write-Host ""
Write-Host "Construyendo frontend para produccion..." -ForegroundColor DarkYellow
Write-Host ""
if (!(Test-Path "frontend/node_modules")) {
Write-Host "ERROR: Dependencias no encontradas" -ForegroundColor Red
Write-Host "Ejecuta primero: .\run.ps1 setup" -ForegroundColor Cyan
return
}
Set-Location frontend
pnpm build
Set-Location ..
Write-Host ""
Write-Host "Build completado" -ForegroundColor Green
Write-Host "Archivos en: frontend/dist/" -ForegroundColor Gray
Write-Host ""
}
function Clean-All {
Write-Host ""
Write-Host "Limpiando archivos temporales..." -ForegroundColor Gray
Write-Host ""
# Python
Write-Host " Limpiando archivos Python..." -ForegroundColor Gray
Get-ChildItem -Path backend -Recurse -Filter "__pycache__" -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force
Get-ChildItem -Path backend -Recurse -Filter "*.pyc" -ErrorAction SilentlyContinue | Remove-Item -Force
# Node
Write-Host " Limpiando archivos Node..." -ForegroundColor Gray
if (Test-Path "frontend/node_modules") {
Remove-Item "frontend/node_modules" -Recurse -Force
}
if (Test-Path "frontend/dist") {
Remove-Item "frontend/dist" -Recurse -Force
}
if (Test-Path "frontend/.vite") {
Remove-Item "frontend/.vite" -Recurse -Force
}
Write-Host ""
Write-Host "Limpieza completada" -ForegroundColor Green
Write-Host "Ejecuta .\run.ps1 setup para reinstalar" -ForegroundColor Cyan
Write-Host ""
}
# Router de comandos
switch ($Command.ToLower()) {
"setup" { Setup-All }
"backend" { Start-Backend }
"frontend" { Start-Frontend }
"migrate" { Run-Migrate }
"migrations" { Create-Migrations }
"superuser" { Create-Superuser }
"test-backend" { Test-Backend }
"test-frontend" { Test-Frontend }
"build" { Build-Frontend }
"clean" { Clean-All }
"help" { Show-Help }
default {
Write-Host ""
Write-Host "ERROR: Comando desconocido - $Command" -ForegroundColor Red
Write-Host ""
Show-Help
}
}