-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
293 lines (255 loc) · 7.66 KB
/
Makefile
File metadata and controls
293 lines (255 loc) · 7.66 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
284
285
286
287
288
289
290
291
292
293
# OctoCAT Supply Chain Management - Makefile
# Supports both template (api-nodejs, api-python) and promoted (api) folder structures within actually rendered repositories for easier startup.
# Allow overriding backend via environment variable (e.g., BACKEND=python make dev)
BACKEND ?= $(shell \
if [ -d "api" ]; then \
if [ -f "api/package.json" ]; then echo "nodejs"; \
elif [ -f "api/pyproject.toml" ]; then echo "python"; \
else echo "unknown"; fi \
elif [ -d "api-nodejs" ] && [ -d "api-python" ]; then echo "nodejs"; \
elif [ -d "api-nodejs" ]; then echo "nodejs"; \
elif [ -d "api-python" ]; then echo "python"; \
else echo "unknown"; fi \
)
# Determine API directory (template vs promoted)
API_DIR := $(shell \
if [ -d "api" ]; then echo "api"; \
elif [ -d "api-$(BACKEND)" ]; then echo "api-$(BACKEND)"; \
else echo "api"; fi \
)
FRONTEND_DIR := frontend
.DEFAULT_GOAL := help
##@ General
.PHONY: help
help: ## Display this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: info
info: ## Show detected backend and directories
@echo "Detected Backend: $(BACKEND)"
@echo "API Directory: $(API_DIR)"
@echo "Frontend Directory: $(FRONTEND_DIR)"
##@ Installation
.PHONY: install
install: ## Install all dependencies
@echo "Installing dependencies for $(BACKEND) backend..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm install
cd $(FRONTEND_DIR) && npm install
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) venv
cd $(FRONTEND_DIR) && npm install
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
##@ Development
.PHONY: dev
dev: ## Start development servers (API + Frontend)
@echo "Starting development environment with $(BACKEND) backend..."
ifeq ($(BACKEND),nodejs)
@cd $(API_DIR)
@trap 'kill 0' INT; \
(cd $(API_DIR) && npm run dev) & \
(cd $(FRONTEND_DIR) && VITE_API_URL=http://localhost:3000 npm run dev) & \
wait
else ifeq ($(BACKEND),python)
@$(MAKE) -C $(API_DIR) db-seed
@trap 'kill 0' INT; \
(cd $(API_DIR) && $(MAKE) dev) & \
(cd $(FRONTEND_DIR) && VITE_API_URL=http://localhost:3000 npm run dev) & \
wait
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: dev-api
dev-api: ## Start only the API development server
@echo "Starting API development server ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run dev
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) dev
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: dev-frontend
dev-frontend: ## Start only the frontend development server
@echo "Starting frontend development server..."
cd $(FRONTEND_DIR) && VITE_API_URL=http://localhost:3000 npm run dev
##@ Database
.PHONY: db-init
db-init: ## Initialize database schema
@echo "Initializing database ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run db:init
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) db-init
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: db-seed
db-seed: ## Initialize and seed database with sample data
@echo "Seeding database ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run db:seed
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) db-seed
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
##@ Building
.PHONY: build
build: ## Build all projects
@echo "Building projects ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run build
cd $(FRONTEND_DIR) && npm run build
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) build
cd $(FRONTEND_DIR) && npm run build
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: build-api
build-api: ## Build only the API
@echo "Building API ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run build
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) build
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: build-frontend
build-frontend: ## Build only the frontend
@echo "Building frontend..."
cd $(FRONTEND_DIR) && npm run build
##@ Testing
.PHONY: test
test: ## Run all tests
@echo "Running tests ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run test
cd $(FRONTEND_DIR) && npm run test
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) test
cd $(FRONTEND_DIR) && npm run test
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: test-api
test-api: ## Run API tests
@echo "Running API tests ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run test
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) test
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: test-frontend
test-frontend: ## Run frontend tests
@echo "Running frontend tests..."
cd $(FRONTEND_DIR) && npm run test
.PHONY: test-e2e
test-e2e: ## Run end-to-end tests
@echo "Running E2E tests..."
cd $(FRONTEND_DIR) && npm run test:e2e
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run test:coverage
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) test-coverage
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
##@ Linting
.PHONY: lint
lint: ## Lint all code
@echo "Linting code ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run lint
cd $(FRONTEND_DIR) && npm run lint
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) lint
cd $(FRONTEND_DIR) && npm run lint
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: lint-fix
lint-fix: ## Lint and auto-fix issues
@echo "Linting and fixing code ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm run lint:fix
cd $(FRONTEND_DIR) && npm run lint -- --fix
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) lint-fix
cd $(FRONTEND_DIR) && npm run lint -- --fix
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
.PHONY: format
format: ## Format code with prettier/ruff
@echo "Formatting code ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
npx prettier --write "$(API_DIR)/**/*.{ts,tsx}" "$(FRONTEND_DIR)/**/*.{ts,vue}"
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) format
cd $(FRONTEND_DIR) && npx prettier --write "src/**/*.{ts,vue}"
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
##@ Production
.PHONY: start
start: ## Start production server
@echo "Starting production server ($(BACKEND))..."
ifeq ($(BACKEND),nodejs)
cd $(API_DIR) && npm start
else ifeq ($(BACKEND),python)
cd $(API_DIR) && $(MAKE) start
else
@echo "Error: Unknown backend '$(BACKEND)'"
@exit 1
endif
##@ Docker
.PHONY: docker-build
docker-build: ## Build Docker images
@echo "Building Docker images..."
docker-compose build
.PHONY: docker-up
docker-up: ## Start Docker containers
@echo "Starting Docker containers..."
docker-compose up
.PHONY: docker-down
docker-down: ## Stop Docker containers
@echo "Stopping Docker containers..."
docker-compose down
##@ Cleaning
.PHONY: clean
clean: ## Clean build artifacts and dependencies
@echo "Cleaning build artifacts..."
ifeq ($(BACKEND),nodejs)
rm -rf node_modules $(API_DIR)/node_modules $(FRONTEND_DIR)/node_modules
rm -rf $(API_DIR)/dist $(FRONTEND_DIR)/dist
else ifeq ($(BACKEND),python)
rm -rf $(API_DIR)/.venv $(API_DIR)/__pycache__ $(API_DIR)/src/__pycache__
rm -rf $(API_DIR)/.pytest_cache $(API_DIR)/htmlcov $(API_DIR)/.coverage
rm -rf $(FRONTEND_DIR)/node_modules $(FRONTEND_DIR)/dist
else
@echo "Cleaning common artifacts..."
rm -rf */node_modules */dist */__pycache__ */.venv
endif
rm -rf $(API_DIR)/*.db $(API_DIR)/*.db-*