-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathMakefile
More file actions
236 lines (184 loc) · 8.54 KB
/
Makefile
File metadata and controls
236 lines (184 loc) · 8.54 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
# =============================================================================
# StellarEarn Backend — Makefile
# Shortcut runner for common NestJS/Prisma/Docker backend workflows
# Usage: make <target>
# =============================================================================
# ── Configuration ─────────────────────────────────────────────────────────────
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Package manager (override: make install PM=npm)
PM ?= pnpm
# Docker Compose file
DC := docker compose -f infra/docker-compose.yml
# Colors for pretty output
CYAN := \033[0;36m
GREEN := \033[0;32m
YELLOW:= \033[0;33m
RESET := \033[0m
# ── Help ──────────────────────────────────────────────────────────────────────
.PHONY: help
help: ## Show this help message
@echo ""
@echo " $(CYAN)StellarEarn — Backend Task Runner$(RESET)"
@echo ""
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_\-]+:.*##/ \
{ printf " $(GREEN)%-22s$(RESET) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@echo ""
# ── Installation ──────────────────────────────────────────────────────────────
.PHONY: install
install: ## Install all backend dependencies
cd apps/api && $(PM) install
.PHONY: install-ci
install-ci: ## Install dependencies in frozen/CI mode (no lockfile updates)
cd apps/api && $(PM) install --frozen-lockfile
# ── Development ───────────────────────────────────────────────────────────────
.PHONY: dev
dev: ## Start the backend in watch/dev mode
cd apps/api && $(PM) run start:dev
.PHONY: start
start: ## Start the backend in production mode
cd apps/api && $(PM) run start:prod
.PHONY: build
build: ## Compile TypeScript → dist/
cd apps/api && $(PM) run build
.PHONY: build-watch
build-watch: ## Compile in watch mode
cd apps/api && $(PM) run build -- --watch
# ── Database ──────────────────────────────────────────────────────────────────
.PHONY: db-up
db-up: ## Start Postgres via Docker Compose
$(DC) up -d postgres
.PHONY: db-down
db-down: ## Stop Postgres container
$(DC) stop postgres
.PHONY: db-logs
db-logs: ## Tail Postgres container logs
$(DC) logs -f postgres
.PHONY: db-migrate
db-migrate: ## Run pending Prisma migrations (dev)
cd apps/api && $(PM) exec prisma migrate dev
.PHONY: db-migrate-prod
db-migrate-prod: ## Deploy migrations in production (no prompt)
cd apps/api && $(PM) exec prisma migrate deploy
.PHONY: db-reset
db-reset: ## ⚠ Drop DB, re-run all migrations, and re-seed
cd apps/api && $(PM) exec prisma migrate reset --force
.PHONY: db-seed
db-seed: ## Run Prisma seed script
cd apps/api && $(PM) exec prisma db seed
.PHONY: db-studio
db-studio: ## Open Prisma Studio in the browser
cd apps/api && $(PM) exec prisma studio
.PHONY: db-generate
db-generate: ## Regenerate Prisma client after schema changes
cd apps/api && $(PM) exec prisma generate
.PHONY: db-push
db-push: ## Push Prisma schema to DB without migration files (prototyping)
cd apps/api && $(PM) exec prisma db push
# ── Testing ───────────────────────────────────────────────────────────────────
.PHONY: test
test: ## Run all unit tests
cd apps/api && $(PM) run test
.PHONY: test-watch
test-watch: ## Run unit tests in watch mode
cd apps/api && $(PM) run test:watch
.PHONY: test-cov
test-cov: ## Run unit tests with coverage report
cd apps/api && $(PM) run test:cov
.PHONY: test-e2e
test-e2e: ## Run end-to-end (integration) tests
cd apps/api && $(PM) run test:e2e
.PHONY: test-debug
test-debug: ## Run tests in debug mode (Node inspector)
cd apps/api && $(PM) run test:debug
.PHONY: test-all
test-all: test test-e2e ## Run unit + e2e tests sequentially
# ── Linting & Formatting ──────────────────────────────────────────────────────
.PHONY: lint
lint: ## Lint TypeScript source with ESLint
cd apps/api && $(PM) run lint
.PHONY: lint-fix
lint-fix: ## Lint and auto-fix fixable issues
cd apps/api && $(PM) run lint -- --fix
.PHONY: format
format: ## Format source with Prettier
cd apps/api && $(PM) exec prettier --write "src/**/*.ts" "test/**/*.ts"
.PHONY: typecheck
typecheck: ## Run TypeScript type checking (no emit)
cd apps/api && $(PM) exec tsc --noEmit
.PHONY: check
check: lint typecheck ## Run lint + typecheck together
# ── Docker ────────────────────────────────────────────────────────────────────
.PHONY: docker-up
docker-up: ## Start all Docker Compose services
$(DC) up -d
.PHONY: docker-down
docker-down: ## Stop all Docker Compose services
$(DC) down
.PHONY: docker-rebuild
docker-rebuild: ## Rebuild all images and restart services
$(DC) up -d --build
.PHONY: docker-logs
docker-logs: ## Tail all Docker Compose logs
$(DC) logs -f
.PHONY: docker-ps
docker-ps: ## Show status of Docker Compose services
$(DC) ps
.PHONY: docker-clean
docker-clean: ## Remove containers, networks, and volumes (⚠ data loss)
$(DC) down -v --remove-orphans
# ── Stellar / Soroban ─────────────────────────────────────────────────────────
.PHONY: contract-build
contract-build: ## Build the Soroban/Rust contract
cd contracts/earn-quest && cargo build --release
.PHONY: contract-test
contract-test: ## Run Rust contract unit tests
cd contracts/earn-quest && cargo test
.PHONY: contract-deploy-testnet
contract-deploy-testnet: ## Deploy contract to Stellar testnet
@echo "$(YELLOW)Deploying to testnet…$(RESET)"
soroban contract deploy \
--wasm contracts/earn-quest/target/wasm32-unknown-unknown/release/earn_quest.wasm \
--network testnet \
--secret-key $$SOROBAN_SECRET_KEY \
--rpc-url $$SOROBAN_RPC_URL
.PHONY: contract-fmt
contract-fmt: ## Format Rust contract source
cd contracts/earn-quest && cargo fmt
.PHONY: contract-clippy
contract-clippy: ## Run Clippy lints on contract source
cd contracts/earn-quest && cargo clippy -- -D warnings
# ── Compound / CI shortcuts ───────────────────────────────────────────────────
.PHONY: setup
setup: install db-up db-migrate ## First-time setup: install deps, start DB, run migrations
@echo "$(GREEN)✔ Setup complete. Run 'make dev' to start the backend.$(RESET)"
.PHONY: ci
ci: install-ci lint typecheck test ## Full CI pipeline: install → lint → typecheck → test
.PHONY: ci-full
ci-full: ci test-e2e ## Full CI pipeline including e2e tests
.PHONY: fresh
fresh: docker-clean docker-up db-migrate ## Nuclear reset: wipe Docker volumes, restart, re-migrate
.PHONY: clean
clean: ## Remove compiled artifacts (dist/, coverage/)
rm -rf apps/api/dist apps/api/coverage
.PHONY: nuke
nuke: clean docker-clean ## Remove all build artifacts AND Docker volumes (⚠ use with care)
# ── Utilities ─────────────────────────────────────────────────────────────────
.PHONY: env-check
env-check: ## Verify required environment variables are set
@missing=0; \
for var in DATABASE_URL STELLAR_NETWORK SOROBAN_RPC_URL CONTRACT_ID JWT_SECRET; do \
if [ -z "$${!var}" ]; then \
echo "$(YELLOW)⚠ Missing: $$var$(RESET)"; missing=1; \
else \
echo "$(GREEN)✔ $$var$(RESET)"; \
fi; \
done; \
[ $$missing -eq 0 ] && echo "$(GREEN)All required env vars are set.$(RESET)" \
|| (echo "$(YELLOW)Copy .env.example → apps/api/.env and fill in the blanks.$(RESET)"; exit 1)
.PHONY: logs-api
logs-api: ## Tail the API service logs (Docker)
$(DC) logs -f api
.PHONY: shell-api
shell-api: ## Open a shell inside the running API container
$(DC) exec api /bin/sh