Repository navigation
Expand file tree
/
Copy pathstart-dev.sh
More file actions
executable file
·95 lines (79 loc) · 4.07 KB
/
Copy pathstart-dev.sh
File metadata and controls
executable file
·95 lines (79 loc) · 4.07 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
#!/bin/bash
# ─────────────────────────────────────────────────────────────────
# start-dev.sh — Sincronizar y arrancar servidor de desarrollo
# ─────────────────────────────────────────────────────────────────
cd "$(dirname "$0")" || exit 1
# Colores
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
echo ""
echo -e "${CYAN}🏥 SERVYSALUD360 — Iniciando entorno de desarrollo${NC}"
echo "────────────────────────────────────────────────────"
# ── 1. Sincronizar con repositorio remoto ────────────────────────
echo ""
echo -e "${CYAN}🔄 Sincronizando con el repositorio...${NC}"
# Limpiar referencias remotas obsoletas/corruptas (evita "bad object refs/remotes/origin/main 2")
git remote prune origin 2>/dev/null || true
# Guardar commit actual para detectar cambios
COMMIT_BEFORE=$(git rev-parse HEAD 2>/dev/null)
# Verificar si hay cambios locales sin guardar
if ! git diff --quiet || ! git diff --cached --quiet; then
echo -e "${YELLOW}⚠️ Tienes cambios sin guardar. Ejecuta ./save-work.sh primero.${NC}"
echo -e " Continuando sin hacer pull para no perder cambios..."
else
git pull --ff-only 2>&1
GIT_STATUS=$?
if [ $GIT_STATUS -ne 0 ]; then
echo -e "${YELLOW}⚠️ No se pudo hacer pull automático (puede haber conflictos).${NC}"
echo -e " Revisa con: git status"
else
COMMIT_AFTER=$(git rev-parse HEAD 2>/dev/null)
if [ "$COMMIT_BEFORE" != "$COMMIT_AFTER" ]; then
echo -e "${GREEN}✅ Repositorio actualizado${NC}"
echo -e " $(git log --oneline -1)"
# ── 2. Reinstalar dependencias si package.json cambió ──────
if git diff "$COMMIT_BEFORE" "$COMMIT_AFTER" --name-only 2>/dev/null | grep -q "package.json"; then
echo ""
echo -e "${YELLOW}📦 package.json cambió — instalando dependencias...${NC}"
npm install
fi
else
echo -e "${GREEN}✅ Ya estás al día${NC}"
fi
fi
fi
# ── 2b. Instalar si node_modules no existe (ej: clon fresco en Mac Mini) ──
if [ ! -d "node_modules" ]; then
echo ""
echo -e "${YELLOW}📦 node_modules no existe — instalando dependencias...${NC}"
npm install
fi
# ── 3. Limpiar procesos anteriores ──────────────────────────────
echo ""
echo -e "${CYAN}🧹 Limpiando procesos anteriores...${NC}"
pkill -f "next dev" 2>/dev/null
pkill -f "turbopack" 2>/dev/null
sleep 1
# ── 4. Liberar puertos ───────────────────────────────────────────
echo -e "${CYAN}🔌 Liberando puertos...${NC}"
lsof -ti:3000,3001,3002,3003 2>/dev/null | xargs kill -9 2>/dev/null
sleep 1
# ── 5. Limpiar locks de Turbopack ───────────────────────────────
# /tmp/servysalud-next es el directorio de build (next.config.ts → distDir)
# Los locks LMDB de Turbopack quedan huérfanos si el proceso anterior no terminó limpio.
# Se elimina siempre al iniciar para evitar "Lock broken by another request".
echo -e "${CYAN}🔒 Liberando locks de Turbopack...${NC}"
rm -rf /tmp/servysalud-next 2>/dev/null || true
# También limpiar el directorio .nosync si existe
rm -rf .next.nosync 2>/dev/null || true
# ── 6. Arrancar servidor ─────────────────────────────────────────
echo ""
echo -e "${GREEN}🚀 Iniciando servidor de desarrollo...${NC}"
echo -e " 📍 URL: http://127.0.0.1:3000"
echo -e " ⚠️ Para detener: Ctrl+C"
echo -e " 💡 Si hay errores: ./start-dev.sh (limpia caché automáticamente)"
echo ""
npm run dev