python__django_tutorials/Makefile

72 lines
2.5 KiB
Makefile

# Variables
PYTHON = uv run python
MANAGE = ticketing/manage.py
FRONTEND_DIR = ticketing/ticketing-frontend
.PHONY: help install build check test test-backend test-frontend format format-backend format-frontend lint clean run run-backend run-frontend settings settings-backend settings-frontend migrate secret-key
# --- Help ---
# Modern self-documenting help target (DRY)
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
install: ## Install Python (uv) and Node.js (npm) dependencies
uv sync
cd $(FRONTEND_DIR) && npm install
@echo "Now run 'make migrate' to initialize your database."
build: ## Build the React frontend for production
cd $(FRONTEND_DIR) && npm run build
check: ## Run Django system checks
$(PYTHON) $(MANAGE) check
migrate: ## Run database migrations
$(PYTHON) $(MANAGE) migrate
settings: settings-backend settings-frontend ## Show all settings (backend & frontend)
settings-backend: ## Show Django settings (diff with default)
$(PYTHON) $(MANAGE) diffsettings
settings-frontend: ## Show Vite environment variables
cd $(FRONTEND_DIR) && npm run settings
secret-key: ## Generate a random Django secret key
@$(PYTHON) -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
format: format-backend format-frontend ## Auto-format all code (backend & frontend)
format-backend: ## Auto-format Python code with Ruff
uvx ruff format .
format-frontend: ## Auto-format frontend code with Prettier
cd $(FRONTEND_DIR) && npm run format
lint: format check ## Run all lints (includes format, django check, ruff, and eslint)
uvx ruff check .
cd $(FRONTEND_DIR) && npm run lint
test: test-backend test-frontend ## Run tests for both backend and frontend
test-backend: ## Run Django backend tests
$(PYTHON) $(MANAGE) test ticketing
test-frontend: ## Run Vitest frontend tests
cd $(FRONTEND_DIR) && npm test
run: ## Run all development servers (backend & frontend) in parallel
@echo "Starting backend (Django) and frontend (React) servers..."
@$(MAKE) -j 2 run-backend run-frontend
run-backend: ## Run the Django development server
$(PYTHON) $(MANAGE) runserver
run-frontend: ## Run the React/Vite development server
cd $(FRONTEND_DIR) && npm start
clean: ## Remove build artifacts, node_modules, and __pycache__
rm -rf $(FRONTEND_DIR)/build
rm -rf $(FRONTEND_DIR)/node_modules
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete