-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
290 lines (240 loc) ยท 11.9 KB
/
Makefile
File metadata and controls
290 lines (240 loc) ยท 11.9 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
.PHONY: help setup install proto proto-lint proto-breaking \
dev-infra dev-infra-down dev-infra-logs \
dev-backend build-backend test-backend \
dev-frontend dev-frontend-main dev-frontend-feed \
build-frontend build-preview preview kill-ports \
fmt fmt-check lint typecheck check \
dev dev-full build test test-e2e test-e2e-ui \
clean clean-all \
db-migrate db-migrate-down db-migrate-status db-migrate-fresh db-entity db-reset
# ============================================================
# Luhanxin Community Platform โ ๅผๅๅฝไปค
# ============================================================
# ไป docker/.env ๅ ่ฝฝ้
็ฝฎ๏ผๅฏไธ็็ธๆบ๏ผ๏ผ็ฏๅขๅ้ๅฏ่ฆ็
-include docker/.env
export
# ็ซฏๅฃ้ป่ฎคๅผ๏ผ.env ๆชๅฎไนๆถไฝฟ็จ๏ผ
GATEWAY_PORT ?= 8000
SVC_USER_PORT ?= 50051
SVC_CONTENT_PORT ?= 50052
SVC_NOTIFICATION_PORT ?= 50053
CONSUL_HTTP_PORT ?= 8500
MAIN_PORT ?= 5173
FEED_PORT ?= 5174
USER_PROFILE_PORT ?= 5175
help: ## ๆพ็คบๅธฎๅฉไฟกๆฏ
@echo ""
@echo "\033[1m๐ Luhanxin Community Platform\033[0m"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}'
@echo ""
# ------------------------------------------------------------
# ๅๅงๅ
# ------------------------------------------------------------
setup: ## ้ฆๆฌกๅๅงๅ๏ผๅฎ่ฃ
ๅ
จๅฑๅทฅๅ
ท + ้กน็ฎไพ่ต๏ผๆฐๆๅๅฟ
่ท๏ผ
@echo ""
@echo "\033[1m๐ง Setting up development environment...\033[0m"
@echo ""
@echo "โโ ๆฃๆฅๅ
จๅฑๅทฅๅ
ท โโ"
@command -v rustc >/dev/null 2>&1 || (echo "โ Rust not found. Install: https://rustup.rs" && exit 1)
@command -v node >/dev/null 2>&1 || (echo "โ Node.js not found. Install: https://nodejs.org" && exit 1)
@command -v pnpm >/dev/null 2>&1 || (echo "โ pnpm not found. Install: npm install -g pnpm" && exit 1)
@command -v docker >/dev/null 2>&1 || (echo "โ Docker not found. Install: https://docker.com" && exit 1)
@command -v buf >/dev/null 2>&1 || (echo "โ ๏ธ buf not found. Install: brew install bufbuild/buf/buf")
@echo "โโ ๅฎ่ฃ
Rust CLI ๅทฅๅ
ท โโ"
@command -v sea-orm-cli >/dev/null 2>&1 && echo " โ
sea-orm-cli" || (echo " ๐ฆ Installing sea-orm-cli..." && cargo install sea-orm-cli)
@command -v cargo-watch >/dev/null 2>&1 && echo " โ
cargo-watch" || (echo " ๐ฆ Installing cargo-watch..." && cargo install cargo-watch)
@echo "โโ ๅฎ่ฃ
้กน็ฎไพ่ต โโ"
pnpm install
@echo "โโ ๅๅงๅ Docker ็ฏๅข โโ"
@test -f docker/.env || cp docker/.env.example docker/.env
@echo ""
@echo "\033[1mโ
Setup complete! Next steps:\033[0m"
@echo " 1. make dev-infra โ ๅฏๅจ Docker ๅบ็ก่ฎพๆฝ"
@echo " 2. make db-migrate โ ่ฟ่กๆฐๆฎๅบ่ฟ็งป"
@echo " 3. make dev-backend โ ๅฏๅจๅ็ซฏๆๅก"
@echo " 4. make dev-frontend โ ๅฏๅจๅ็ซฏ"
@echo ""
install: ## ๅฎ่ฃ
้กน็ฎไพ่ต (pnpm install)
pnpm install
# ------------------------------------------------------------
# Protobuf
# ------------------------------------------------------------
proto: ## ็ๆ Protobuf Rust + TypeScript ไปฃ็
@echo "๐ Generating Protobuf code..."
cd proto && buf generate
@echo "๐ง Generating Rust proto mod.rs..."
@bash scripts/gen-proto-mod.sh
@echo "โ
Protobuf code generated"
proto-lint: ## ๆฃๆฅ Proto ๆไปถ่ง่
cd proto && buf lint
proto-breaking: ## ๆฃๆต Proto ไธๅ
ผๅฎนๅๆด
cd proto && buf breaking --against '.git#subdir=proto'
# ------------------------------------------------------------
# Docker ๅบ็ก่ฎพๆฝ
# ------------------------------------------------------------
dev-infra: ## ๅฏๅจ Docker ๆฐๆฎไพ่ต (PostgreSQL + Redis + Meilisearch)
@echo "๐ณ Starting infrastructure..."
@test -f docker/.env || cp docker/.env.example docker/.env
cd docker && docker compose up -d
@echo "โ
Infrastructure started"
dev-infra-down: ## ๅๆญข Docker ๆฐๆฎไพ่ต
cd docker && docker compose down
dev-infra-logs: ## ๆฅ็ Docker ๅฎนๅจๆฅๅฟ
cd docker && docker compose logs -f
# ------------------------------------------------------------
# ๅ็ซฏ
# ------------------------------------------------------------
dev-backend: ## ๅฏๅจๅ็ซฏๆๅก (Gateway + svc-user + svc-content + svc-notification, ๆ cargo-watch ๅ็ญ้่ฝฝ)
@echo ""
@echo "\033[1m๐ฆ Starting backend services...\033[0m"
@echo ""
@if command -v cargo-watch >/dev/null 2>&1; then \
echo " โ Using cargo-watch (hot-reload enabled)"; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo watch -q -x 'run --bin svc-user' 2>&1 | sed 's/^/ [svc-user] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo watch -q -x 'run --bin svc-content' 2>&1 | sed 's/^/ [svc-content] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo watch -q -x 'run --bin svc-notification' 2>&1 | sed 's/^/ [svc-notif] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo watch -q -x 'run --bin gateway' 2>&1 | sed 's/^/ [gateway] /' & \
else \
echo " โ ๏ธ cargo-watch not installed, starting without hot-reload"; \
echo " ๐ก Install: cargo install cargo-watch"; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo run --bin svc-user 2>&1 | sed 's/^/ [svc-user] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo run --bin svc-content 2>&1 | sed 's/^/ [svc-content] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo run --bin svc-notification 2>&1 | sed 's/^/ [svc-notif] /' & \
sleep 2; \
RUST_LOG=gateway=info,svc_user=info,svc_content=info,svc_notification=info,shared=info cargo run --bin gateway 2>&1 | sed 's/^/ [gateway] /' & \
fi
@sleep 5
@echo ""
@echo "\033[1mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\033[0m"
@echo "\033[1mโ ๐ฆ Backend Services Ready โ\033[0m"
@echo "\033[1mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค\033[0m"
@echo " Gateway: \033[36mhttp://localhost:$(GATEWAY_PORT)\033[0m"
@echo " Swagger: \033[36mhttp://localhost:$(GATEWAY_PORT)/swagger-ui/\033[0m"
@echo " Health: \033[36mhttp://localhost:$(GATEWAY_PORT)/health\033[0m"
@echo " svc-user: \033[36mlocalhost:$(SVC_USER_PORT)\033[0m (gRPC)"
@echo " svc-content: \033[36mlocalhost:$(SVC_CONTENT_PORT)\033[0m (gRPC)"
@echo " svc-notif: \033[36mlocalhost:$(SVC_NOTIFICATION_PORT)\033[0m (gRPC)"
@echo " Consul UI: \033[36mhttp://localhost:$(CONSUL_HTTP_PORT)\033[0m"
@echo "\033[1mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\033[0m"
@echo ""
build-backend: ## ๆๅปบๅ็ซฏ (release)
cargo build --release
test-backend: ## ่ฟ่กๅ็ซฏๆต่ฏ
cargo test --all-targets
# ------------------------------------------------------------
# ๅ็ซฏ
# ------------------------------------------------------------
dev-frontend: ## ๅฏๅจๅ็ซฏๆๆๅญๅบ็จ (้่ฟ dev.sh, ๆจ่)
@echo ""
@echo "\033[1mโ๏ธ Starting frontend apps...\033[0m"
@echo ""
@echo ""
@bash scripts/dev.sh
dev-frontend-main: ## ๅชๅฏๅจไธปๅบ็จ (main)
pnpm dev:main
dev-frontend-feed: ## ๅชๅฏๅจ feed ๅญๅบ็จ
pnpm dev:feed
build-frontend: ## ๆๅปบๅ็ซฏๆๆๅ
ๅๅบ็จ
pnpm -r build
build-preview: ## ๆๅปบๅ็ซฏๅนถ็ป่ฃ
preview ็ฎๅฝ (ๅญๅบ็จ โ main/dist/apps/)
@bash scripts/build-preview.sh
preview: build-preview ## ๆๅปบๅนถๅฏๅจ preview server (้ช่ฏ็ไบงๆๆ)
@echo "๐ Starting preview server on http://localhost:4173 ..."
pnpm --filter @luhanxin/main preview
test-e2e: ## ่ฟ่ก Playwright E2E ๆต่ฏ
pnpm test:e2e
test-e2e-ui: ## ๆๅผ Playwright UI ๆจกๅผ
pnpm test:e2e:ui
# ------------------------------------------------------------
# ไปฃ็ ่ดจ้
# ------------------------------------------------------------
fmt: ## ๆ ผๅผๅๆๆไปฃ็ (Rust + TypeScript)
cargo fmt --all
pnpm format
fmt-check: ## ๆฃๆฅๆ ผๅผๅ (CI ็จ)
cargo fmt --all -- --check
pnpm format:check
lint: proto-lint ## ่ฟ่กๆๆ lint ๆฃๆฅ
@echo "๐ Running lints..."
cargo clippy --all-targets --all-features -- -D warnings
pnpm lint
@echo "โ
All lints passed"
typecheck: ## TypeScript ็ฑปๅๆฃๆฅ
pnpm typecheck
check: fmt-check lint typecheck ## ๅฎๆดๆฃๆฅ (CI ๆตๆฐด็บฟ)
@echo "โ
All checks passed"
# ------------------------------------------------------------
# ๅ
จๅฑๅฝไปค
# ------------------------------------------------------------
dev: ## ไธ้ฎๅฏๅจๅ็ซฏ (ๆธ
็ๆณจๅ่กจ + ๅนถ่กๅฏๅจๆๆๅญๅบ็จ, ๆฅๅธธๆจ่)
@bash scripts/dev.sh
dev-full: dev-infra ## ไธ้ฎๅฏๅจๅ
จๆ (ๅบ็ก่ฎพๆฝ + ๅ็ซฏ + ๅ็ซฏ)
@sleep 3
@$(MAKE) dev-backend
@sleep 2
@$(MAKE) dev-frontend
build: build-backend build-frontend ## ๆๅปบๅ
จ้จ (ๅ็ซฏ + ๅ็ซฏ)
test: test-backend ## ่ฟ่กๆๆๆต่ฏ (ๅๅ
+ E2E)
pnpm test
@$(MAKE) test-e2e
kill-ports: ## ๆๆ้กน็ฎๅ ็จ็็ซฏๅฃ่ฟ็จ (8000,50051,50052,50053,5173,5174,4173)
@echo "๐ช Killing processes on project ports..."
@for port in 8000 50051 50052 50053 5173 5174 4173; do \
pid=$$(lsof -ti:$$port 2>/dev/null); \
if [ -n "$$pid" ]; then \
echo " โ port $$port: killing PID $$pid"; \
kill $$pid 2>/dev/null; \
else \
echo " โ port $$port: ็ฉบ้ฒ"; \
fi; \
done
@echo "โ
Ports cleared"
clean: ## ๆธ
็ๆๅปบไบง็ฉ (ไฟ็ node_modules)
@echo "๐งน Cleaning build artifacts..."
cargo clean
rm -rf apps/*/dist packages/*/dist
rm -f .dev-registry.json
@echo "โ
Clean complete"
clean-all: clean ## ๆทฑๅบฆๆธ
็ (ๅซ node_modules + ๆ็ซฏๅฃ่ฟ็จ, ้่ฆ้ๆฐ install)
@echo "๐งน Killing processes on project ports (8000,50051,50052,50053,5173,5174,4173)..."
@-lsof -ti:8000,50051,50052,50053,5173,5174,4173 2>/dev/null | xargs kill 2>/dev/null; true
@echo "๐งน Deep cleaning..."
rm -rf node_modules apps/*/node_modules packages/*/node_modules
@echo "โ
Deep clean complete. Run 'make install' to reinstall."
# ------------------------------------------------------------
# ๆฐๆฎๅบ
# ------------------------------------------------------------
DATABASE_URL ?= postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@localhost:$(POSTGRES_PORT)/$(POSTGRES_DB)
db-migrate: ## ่ฟ่กๆฐๆฎๅบ่ฟ็งป (ๅไธ)
@echo "๐ Running database migrations..."
DATABASE_URL=$(DATABASE_URL) cargo run -p migration -- up
@echo "โ
Migrations applied"
db-migrate-down: ## ๅๆปๆ่ฟไธๆฌก่ฟ็งป
@echo "๐ Rolling back last migration..."
DATABASE_URL=$(DATABASE_URL) cargo run -p migration -- down -n 1
@echo "โ
Rolled back 1 migration"
db-migrate-status: ## ๆฅ็่ฟ็งป็ถๆ
DATABASE_URL=$(DATABASE_URL) cargo run -p migration -- status
db-migrate-fresh: ## ้ๅปบๆฐๆฎๅบ (drop all + re-migrate, ๅผๅ็จ)
@echo "โ ๏ธ Dropping all tables and re-running migrations..."
DATABASE_URL=$(DATABASE_URL) cargo run -p migration -- fresh
@echo "โ
Database freshly migrated"
db-entity: ## ไปๆฐๆฎๅบ็ๆ SeaORM Entity ไปฃ็
@echo "๐ง Generating entities from database..."
sea-orm-cli generate entity \
-u $(DATABASE_URL) \
-o crates/shared/src/entity \
--with-serde both
@echo "โ
Entities generated"
db-reset: ## ้็ฝฎๆฐๆฎๅบ (drop + create + migrate)
@echo "โ ๏ธ Resetting database..."
@docker exec luhanxin-postgres psql -U luhanxin -c "DROP DATABASE IF EXISTS luhanxin_community;" 2>/dev/null || true
@docker exec luhanxin-postgres psql -U luhanxin -c "CREATE DATABASE luhanxin_community;" 2>/dev/null || true
@$(MAKE) db-migrate
@echo "โ
Database reset complete"