.PHONY: help setup run \
test test/dominio test/aplicacion test/infraestructura \
lint format format/fix check clean clean/incremental \
audit audit/fix \
generar/entidad generar/caso-de-uso generar/bootstrap \
web/install web/require-install web/dev web/test web/lint web/sync
CARGO := cargo
BUN := bun
GREEN := $(shell printf '\033[1;32m')
YELLOW := $(shell printf '\033[1;33m')
CYAN := $(shell printf '\033[1;36m')
RED := $(shell printf '\033[1;31m')
NC := $(shell printf '\033[0m')
help:
@echo ""
@echo "${CYAN}Comandos disponibles:${NC}"
@echo ""
@grep -E '^[a-zA-Z/_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " ${YELLOW}%-32s${NC} %s\n", $$1, $$2}'
@echo ""
setup:
@echo "${CYAN}Preparando el entorno de desarrollo...${NC}"
$(CARGO) install cargo-nextest --locked
$(CARGO) install cargo-audit --locked
run:
@echo "${GREEN}Arrancando el servidor de la API (en memoria: los datos se pierden al reiniciar)...${NC}"
$(CARGO) run -p api
test:
@echo "${YELLOW}Ejecutando todos los tests...${NC}"
$(CARGO) nextest run --workspace
@if [ -d web ]; then $(MAKE) web/test; fi
test/dominio:
@echo "${YELLOW}Ejecutando los tests de dominio...${NC}"
$(CARGO) nextest run --workspace -E 'package(dominio_*)' --no-tests=warn
test/aplicacion:
@echo "${YELLOW}Ejecutando los tests de aplicación...${NC}"
$(CARGO) nextest run --workspace -E 'package(aplicacion_*)' --no-tests=warn
test/infraestructura:
@echo "${YELLOW}Ejecutando los tests de infraestructura...${NC}"
$(CARGO) nextest run --workspace -E 'package(infra_*)' --no-tests=warn
lint:
@echo "${CYAN}Pasando el lint...${NC}"
$(CARGO) clippy --workspace --all-targets -- -D warnings
@if [ -d web ]; then $(MAKE) web/lint; fi
format:
@echo "${CYAN}Comprobando el formato...${NC}"
$(CARGO) fmt --all -- --check
format/fix:
@echo "${CYAN}Corrigiendo el formato...${NC}"
$(CARGO) fmt --all
check:
@echo "${CYAN}Comprobando el código...${NC}"
$(CARGO) check --workspace
clean:
@echo "${RED}Borrando lo compilado...${NC}"
$(CARGO) clean
clean/incremental:
@echo "${RED}Borrando las cachés incrementales...${NC}"
rm -rf target/debug/incremental target/release/incremental
audit:
@echo "${CYAN}Auditando la seguridad...${NC}"
$(CARGO) audit
audit/fix:
@echo "${CYAN}Arreglos de seguridad (dry-run)...${NC}"
$(CARGO) audit fix --dry-run
generar/entidad: ## Genera una entidad DDD nueva — make generar/entidad NOMBRE=Producto
@if [ -z "$$NOMBRE" ]; then \
echo "${RED}Error: falta el nombre de la entidad — make generar/entidad NOMBRE=Producto${NC}"; \
exit 1; \
fi
@echo "${GREEN}Generando la entidad '$$NOMBRE'...${NC}"
puerto generar scaffold $$NOMBRE
generar/caso-de-uso: ## Añade un caso de uso a una entidad — make generar/caso-de-uso ENTIDAD=Producto ACCION=publicar_producto
@if [ -z "$$ENTIDAD" ] || [ -z "$$ACCION" ]; then \
echo "${RED}Error: faltan la entidad y la acción — make generar/caso-de-uso ENTIDAD=Producto ACCION=publicar_producto${NC}"; \
exit 1; \
fi
@echo "${GREEN}Añadiendo el caso de uso '$$ACCION' a '$$ENTIDAD'...${NC}"
puerto generar caso-de-uso $$ENTIDAD $$ACCION
generar/bootstrap:
@echo "${GREEN}Regenerando bootstrap.rs...${NC}"
puerto generar bootstrap
web/install:
@echo "${CYAN}Instalando las dependencias del frontend...${NC}"
cd web && $(BUN) install
web/require-install:
@if [ ! -d web/node_modules ]; then \
echo "${RED}Falta web/node_modules — ejecuta: make web/install${NC}"; \
exit 1; \
fi
web/dev: web/require-install
@echo "${GREEN}Arrancando el servidor de desarrollo del frontend...${NC}"
cd web && $(BUN) run dev
web/test: web/require-install
@echo "${YELLOW}Ejecutando los tests del frontend...${NC}"
cd web && $(BUN) test
web/lint: web/require-install
@echo "${CYAN}Pasando el lint del frontend...${NC}"
cd web && $(BUN) run typecheck && $(BUN) run lint && $(BUN) run lint:arch
web/sync: web/require-install
@echo "${CYAN}Exportando docs/api/openapi.json...${NC}"
UPDATE_OPENAPI=1 $(CARGO) test -p api openapi
@echo "${CYAN}Generando web/src/infrastructure/http/schema.d.ts...${NC}"
cd web && $(BUN) run openapi:types
@echo "${CYAN}Formateando web/ (Biome, sin arreglos de lint)...${NC}"
cd web && $(BUN) run format