codigo0/scripts/cleanup-safe.sh

78 lines
2.8 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Script de limpieza segura - EJECUTAR CON CUIDADO
set -e
echo "🧹 Iniciando limpieza del proyecto..."
echo "⚠️ Este script eliminará archivos. Revisa antes de continuar."
read -p "¿Continuar? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo "❌ Limpieza cancelada"
exit 1
fi
# 1. Eliminar dist/ (se regenera)
if [ -d "dist" ]; then
echo "🗑️ Eliminando dist/..."
rm -rf dist/
echo "✅ dist/ eliminado"
fi
# 2. Eliminar logs
if [ -d "logs" ]; then
echo "🗑️ Limpiando logs..."
rm -f logs/*.log
echo "✅ Logs eliminados"
fi
# 3. Eliminar archivos .backup
echo "🗑️ Eliminando archivos .backup..."
BACKUP_FILES=$(find . -name "*.backup" -not -path "./node_modules/*" -not -path "./.git/*" 2>/dev/null | wc -l)
if [ "$BACKUP_FILES" -gt 0 ]; then
find . -name "*.backup" -not -path "./node_modules/*" -not -path "./.git/*" -delete
echo "$BACKUP_FILES archivo(s) .backup eliminado(s)"
else
echo " No se encontraron archivos .backup"
fi
# 4. Eliminar carpetas vacías (excepto .git)
echo "🗑️ Eliminando carpetas vacías..."
EMPTY_DIRS=$(find . -type d -empty -not -path "./.git/*" -not -path "./node_modules/*" 2>/dev/null | wc -l)
if [ "$EMPTY_DIRS" -gt 0 ]; then
find . -type d -empty -not -path "./.git/*" -not -path "./node_modules/*" -delete
echo "$EMPTY_DIRS carpeta(s) vacía(s) eliminada(s)"
else
echo " No se encontraron carpetas vacías"
fi
# 5. Limpiar Python cache
echo "🗑️ Limpiando __pycache__..."
PYCACHE_DIRS=$(find . -type d -name "__pycache__" -not -path "./node_modules/*" 2>/dev/null | wc -l)
if [ "$PYCACHE_DIRS" -gt 0 ]; then
find . -type d -name "__pycache__" -not -path "./node_modules/*" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -not -path "./node_modules/*" -delete 2>/dev/null || true
echo "✅ Python cache limpiado"
else
echo " No se encontró Python cache"
fi
# 6. Limpiar archivos temporales
echo "🗑️ Eliminando archivos temporales..."
TEMP_FILES=$(find . -name "*.tmp" -o -name "*.temp" -o -name ".DS_Store" -o -name "Thumbs.db" 2>/dev/null | grep -v node_modules | grep -v .git | wc -l)
if [ "$TEMP_FILES" -gt 0 ]; then
find . -name "*.tmp" -o -name "*.temp" -o -name ".DS_Store" -o -name "Thumbs.db" 2>/dev/null | \
grep -v node_modules | grep -v .git | xargs rm -f 2>/dev/null || true
echo "$TEMP_FILES archivo(s) temporal(es) eliminado(s)"
else
echo " No se encontraron archivos temporales"
fi
echo ""
echo "✅ Limpieza completada"
echo ""
echo "📋 Próximos pasos recomendados:"
echo " 1. Ejecutar 'npx depcheck' para verificar dependencias no usadas"
echo " 2. Ejecutar 'npx ts-prune' para detectar código muerto"
echo " 3. Verificar que .gitignore incluye: dist/, logs/, *.backup"