-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
283 lines (225 loc) · 10.4 KB
/
Copy pathMakefile
File metadata and controls
283 lines (225 loc) · 10.4 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
# LandAgro Development Makefile
# Common development tasks automation
.PHONY: help install install-backend install-frontend lint lint-backend lint-frontend \
format format-backend format-frontend test test-backend test-frontend test-e2e \
test-coverage clean clean-backend clean-frontend dev dev-backend dev-frontend \
build pre-commit setup-hooks type-check mypy validate db-migrate
# Default target
.DEFAULT_GOAL := help
# Colors for terminal output
BLUE := \033[34m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
NC := \033[0m # No Color
# ============================================================================
# HELP
# ============================================================================
help: ## Show this help message
@echo "$(BLUE)LandAgro Development Commands$(NC)"
@echo ""
@echo "$(GREEN)Usage:$(NC) make [target]"
@echo ""
@echo "$(YELLOW)Available targets:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
# ============================================================================
# INSTALLATION
# ============================================================================
install: install-backend install-frontend setup-hooks ## Install all dependencies
install-backend: ## Install backend Python dependencies
@echo "$(BLUE)Installing backend dependencies...$(NC)"
cd backend && pip install -r requirements.txt
cd backend && pip install ruff mypy pytest pytest-cov
@echo "$(GREEN)Backend dependencies installed$(NC)"
install-frontend: ## Install frontend Node.js dependencies
@echo "$(BLUE)Installing frontend dependencies...$(NC)"
cd frontend && npm ci
@echo "$(GREEN)Frontend dependencies installed$(NC)"
setup-hooks: ## Setup pre-commit hooks
@echo "$(BLUE)Setting up pre-commit hooks...$(NC)"
pip install pre-commit
pre-commit install
@echo "$(GREEN)Pre-commit hooks installed$(NC)"
# ============================================================================
# LINTING
# ============================================================================
lint: lint-backend lint-frontend ## Run all linters
lint-backend: ## Lint backend Python code with Ruff
@echo "$(BLUE)Linting backend...$(NC)"
cd backend && ruff check src/
@echo "$(GREEN)Backend lint complete$(NC)"
lint-frontend: ## Lint frontend TypeScript code with ESLint
@echo "$(BLUE)Linting frontend...$(NC)"
cd frontend && npm run lint
@echo "$(GREEN)Frontend lint complete$(NC)"
lint-fix: ## Fix linting issues automatically
@echo "$(BLUE)Fixing lint issues...$(NC)"
cd backend && ruff check src/ --fix
cd frontend && npm run lint:fix
@echo "$(GREEN)Lint fixes applied$(NC)"
# ============================================================================
# FORMATTING
# ============================================================================
format: format-backend format-frontend ## Format all code
format-backend: ## Format backend Python code with Ruff
@echo "$(BLUE)Formatting backend...$(NC)"
cd backend && ruff format src/
@echo "$(GREEN)Backend formatted$(NC)"
format-frontend: ## Format frontend code with Prettier
@echo "$(BLUE)Formatting frontend...$(NC)"
cd frontend && npm run format
@echo "$(GREEN)Frontend formatted$(NC)"
format-check: ## Check formatting without making changes
@echo "$(BLUE)Checking formatting...$(NC)"
cd backend && ruff format --check src/
cd frontend && npm run format:check
@echo "$(GREEN)Format check complete$(NC)"
# ============================================================================
# TYPE CHECKING
# ============================================================================
type-check: mypy type-check-frontend ## Run all type checks
mypy: ## Run mypy type checking on backend
@echo "$(BLUE)Running mypy type check...$(NC)"
cd backend && mypy src/
@echo "$(GREEN)Mypy check complete$(NC)"
type-check-frontend: ## TypeScript type checking
@echo "$(BLUE)Running TypeScript type check...$(NC)"
cd frontend && npm run type-check
@echo "$(GREEN)TypeScript check complete$(NC)"
generate-types: ## Generate API types from OpenAPI spec
@echo "$(BLUE)Generating API types...$(NC)"
cd frontend && npm run generate-types
@echo "$(GREEN)API types generated$(NC)"
# ============================================================================
# TESTING
# ============================================================================
test: test-backend test-frontend ## Run all tests
test-backend: ## Run backend Python tests
@echo "$(BLUE)Running backend tests...$(NC)"
cd backend && pytest tests/ -v --tb=short
@echo "$(GREEN)Backend tests complete$(NC)"
test-frontend: ## Run frontend tests
@echo "$(BLUE)Running frontend tests...$(NC)"
cd frontend && npm test
@echo "$(GREEN)Frontend tests complete$(NC)"
test-coverage: ## Run tests with coverage
@echo "$(BLUE)Running tests with coverage...$(NC)"
cd backend && pytest tests/ --cov=src --cov-report=html --cov-report=term
@echo "$(GREEN)Coverage report generated$(NC)"
test-e2e: ## Run Playwright end-to-end tests
@echo "$(BLUE)Running E2E tests...$(NC)"
cd frontend && npx playwright test
@echo "$(GREEN)E2E tests complete$(NC)"
# ============================================================================
# VALIDATION (Full Quality Check)
# ============================================================================
validate: ## Run all quality checks (lint, format, types, banned-actives)
@echo "$(BLUE)Running full validation...$(NC)"
@echo ""
@echo "$(YELLOW)1/5 Backend lint...$(NC)"
@cd backend && ruff check src/ || true
@echo ""
@echo "$(YELLOW)2/5 Backend format check...$(NC)"
@cd backend && ruff format --check src/ || true
@echo ""
@echo "$(YELLOW)3/5 Frontend lint...$(NC)"
@cd frontend && npm run lint || true
@echo ""
@echo "$(YELLOW)4/5 Frontend type check...$(NC)"
@cd frontend && npm run type-check || true
@echo ""
@echo "$(YELLOW)5/5 Banned-actives check (LT/EU regulatory)...$(NC)"
@python scripts/check_banned_actives.py || true
@echo ""
@echo "$(GREEN)Validation complete$(NC)"
check-banned-actives: ## Strict scan: fail if backend/src references LT/EU banned actives
@python scripts/check_banned_actives.py
pre-commit: ## Run pre-commit on all files
@echo "$(BLUE)Running pre-commit hooks...$(NC)"
pre-commit run --all-files
@echo "$(GREEN)Pre-commit complete$(NC)"
# ============================================================================
# DEVELOPMENT SERVERS
# ============================================================================
dev: ## Start both backend and frontend development servers
@echo "$(BLUE)Starting development servers...$(NC)"
@echo "$(YELLOW)Use 'make dev-backend' and 'make dev-frontend' in separate terminals$(NC)"
@echo "Or run: make dev-backend & make dev-frontend"
dev-backend: ## Start backend development server
@echo "$(BLUE)Starting backend server on http://localhost:8000$(NC)"
cd backend && uvicorn src.main:app --reload --host 0.0.0.0 --port 8000
dev-frontend: ## Start frontend development server
@echo "$(BLUE)Starting frontend server on http://localhost:3000$(NC)"
cd frontend && npm run dev
# ============================================================================
# BUILD
# ============================================================================
build: build-frontend ## Build for production
build-frontend: ## Build frontend for production
@echo "$(BLUE)Building frontend...$(NC)"
cd frontend && npm run build
@echo "$(GREEN)Frontend build complete$(NC)"
# ============================================================================
# CLEANING
# ============================================================================
clean: clean-backend clean-frontend ## Clean all generated files
clean-backend: ## Clean backend generated files
@echo "$(BLUE)Cleaning backend...$(NC)"
cd backend && rm -rf __pycache__ .pytest_cache .ruff_cache .mypy_cache .coverage htmlcov
find backend -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find backend -type f -name "*.pyc" -delete 2>/dev/null || true
@echo "$(GREEN)Backend cleaned$(NC)"
clean-frontend: ## Clean frontend generated files
@echo "$(BLUE)Cleaning frontend...$(NC)"
cd frontend && rm -rf .next out node_modules/.cache
@echo "$(GREEN)Frontend cleaned$(NC)"
clean-all: clean ## Deep clean including dependencies
@echo "$(BLUE)Deep cleaning...$(NC)"
cd backend && rm -rf .venv venv
cd frontend && rm -rf node_modules
@echo "$(GREEN)Deep clean complete$(NC)"
# ============================================================================
# DATABASE
# ============================================================================
db-migrate: ## Run Alembic database migrations
@echo "$(BLUE)Running database migrations...$(NC)"
cd backend && alembic upgrade head
@echo "$(GREEN)Migrations complete$(NC)"
db-reset: ## Reset database (WARNING: deletes all data)
@echo "$(RED)WARNING: This will delete all database data!$(NC)"
@read -p "Are you sure? [y/N] " confirm && [ "$$confirm" = "y" ] || exit 1
cd backend && rm -f laukio.db
@echo "$(GREEN)Database reset$(NC)"
# ============================================================================
# DOCKER
# ============================================================================
docker-build: ## Build Docker images
@echo "$(BLUE)Building Docker images...$(NC)"
docker-compose build
@echo "$(GREEN)Docker images built$(NC)"
docker-up: ## Start Docker containers
@echo "$(BLUE)Starting Docker containers...$(NC)"
docker-compose up -d
@echo "$(GREEN)Docker containers running$(NC)"
docker-down: ## Stop Docker containers
@echo "$(BLUE)Stopping Docker containers...$(NC)"
docker-compose down
@echo "$(GREEN)Docker containers stopped$(NC)"
docker-logs: ## View Docker logs
docker-compose logs -f
# ============================================================================
# UTILITIES
# ============================================================================
check-deps: ## Check for outdated dependencies
@echo "$(BLUE)Checking backend dependencies...$(NC)"
cd backend && pip list --outdated 2>/dev/null | head -20 || true
@echo ""
@echo "$(BLUE)Checking frontend dependencies...$(NC)"
cd frontend && npm outdated 2>/dev/null | head -20 || true
loc: ## Count lines of code
@echo "$(BLUE)Lines of code:$(NC)"
@echo "Python:"
@find backend/src -name "*.py" | xargs wc -l 2>/dev/null | tail -1 || echo " 0"
@echo "TypeScript/JavaScript:"
@find frontend/src -name "*.ts" -o -name "*.tsx" | xargs wc -l 2>/dev/null | tail -1 || echo " 0"