Files
hunjing/Makefile
T

180 lines
6.5 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ==============================
# 魂镜 · 统一开发入口(rewrite/1.0)
# 所有本地服务的启动 / 测试 / 数据库迁移统一经本文件;
# Docker 编排(基础设施与应用容器)见 AGENTS.md「开发命令」与 docker/README.md。
# ==============================
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m
.PHONY: help \
dev-backend dev-shenshi dev-bff dev-frontend dev-sandbox dev-tianmu dev-yuanqi dev-core dev-all \
db-upgrade db-downgrade db-revision db-current \
test test-backend test-shenshi test-bff test-frontend \
vet-shenshi typecheck-bff \
infra-up app-up app-down \
clean clean-all clean-pyc clean-pytest clean-mypy clean-empty-dirs clean-dry-run
# 默认目标
help:
@echo "$(GREEN)魂镜统一开发入口$(NC)"
@echo ""
@echo "$(YELLOW)服务启动(开发)$(NC)"
@echo " make dev-backend 灵台(uvicorn 热重载,:8000)"
@echo " make dev-shenshi 神识(go run,:8080)"
@echo " make dev-bff 照壁(tsx watch,:3000)"
@echo " make dev-frontend 琉璃镜(next dev,:3001)"
@echo " make dev-sandbox 乾坤沙箱(cargo run,:8090)"
@echo " make dev-tianmu 天目 OCR(:8101,可选)"
@echo " make dev-yuanqi 元炁本地推理(:11434,可选)"
@echo " make dev-core 核心三服务并行(灵台+神识+照壁)"
@echo " make dev-all 前述全部并行(不含沙箱/天目/元炁)"
@echo ""
@echo "$(YELLOW)数据库(Alembic,迁移编号 000/001/002…)$(NC)"
@echo " make db-upgrade 升级到最新(head)"
@echo " make db-downgrade 回退一步"
@echo " make db-revision m=\"说明\" 生成下一号迁移(自动编号+autogenerate)"
@echo " make db-current 查看当前版本"
@echo ""
@echo "$(YELLOW)测试与检查$(NC)"
@echo " make test 全部(后端+神识+照壁+前端)"
@echo " make test-backend / test-shenshi / test-bff / test-frontend"
@echo " make vet-shenshi go vet"
@echo " make typecheck-bff tsc --noEmit"
@echo ""
@echo "$(YELLOW)Docker 编排快捷方式$(NC)"
@echo " make infra-up / app-up / app-down"
@echo ""
@echo "$(YELLOW)清理$(NC)"
@echo " make clean / clean-all / clean-dry-run"
# ============================== 服务启动(开发) ==============================
dev-backend:
cd backend && uv run python -m app.main
dev-shenshi:
cd shenshi && go run .
dev-bff:
cd bff && npm run dev
dev-frontend:
cd frontend && pnpm dev
dev-sandbox:
cd sandbox && cargo run
dev-tianmu:
cd tianmu && uv run python -m src.main
dev-yuanqi:
cd yuanqi && uv run python -m src.main
# 核心三服务并行:灵台 + 神识 + 照壁(M0 验收链路)
dev-core:
$(MAKE) -j3 dev-backend dev-shenshi dev-bff
dev-all:
$(MAKE) -j4 dev-backend dev-shenshi dev-bff dev-frontend
# ============================== 数据库(Alembic) ==============================
# 迁移约定:revision id 与文件名前缀用三位顺序号(000、001、002…),生成统一走
# `make db-revision`(自动取最大号+1 并传 --rev-id);不要手写哈希 id。
db-upgrade:
cd backend && uv run alembic upgrade head
db-downgrade:
cd backend && uv run alembic downgrade -1
db-revision:
@next=$$(ls backend/alembic/versions 2>/dev/null | grep -E '^[0-9][0-9][0-9]_.*\.py$$' | cut -c1-3 | sort -n | tail -1); \
if [ -z "$$next" ]; then echo "未找到顺序编号迁移,请先确认基线 000 存在"; exit 1; fi; \
next=$$(printf '%03d' $$((10#$$next + 1))); \
echo "$(GREEN)生成迁移 $(NC)$$next:$(m)"; \
cd backend && uv run alembic revision --autogenerate --rev-id $$next -m "$(m)"
db-current:
cd backend && uv run alembic current
# ============================== 测试与检查 ==============================
test-backend:
cd backend && uv run pytest -q
test-shenshi:
cd shenshi && go test ./...
test-bff:
cd bff && npm test --silent
test-frontend:
cd frontend && pnpm test
test: test-backend test-shenshi test-bff test-frontend
vet-shenshi:
cd shenshi && go vet ./...
typecheck-bff:
cd bff && npm run type-check --silent
# ============================== Docker 编排快捷方式 ==============================
infra-up:
docker compose -f docker/docker-compose.infra.yml up -d
app-up:
docker compose -f docker/docker-compose.app.yml up -d --build
app-down:
docker compose -f docker/docker-compose.app.yml down
# ============================== 清理(保留原有能力) ==============================
clean: clean-pyc clean-pytest clean-mypy clean-empty-dirs
@echo "$(GREEN)✓ Cleanup completed successfully!$(NC)"
clean-pyc:
@echo "$(YELLOW)Removing Python cache files...$(NC)"
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@find . -type f -name "*.pyo" -delete 2>/dev/null || true
@find . -type f -name "*.pyd" -delete 2>/dev/null || true
@echo "$(GREEN)✓ Python cache files removed$(NC)"
clean-pytest:
@echo "$(YELLOW)Removing pytest cache...$(NC)"
@rm -rf .pytest_cache 2>/dev/null || true
@find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
@echo "$(GREEN)✓ Pytest cache removed$(NC)"
clean-mypy:
@echo "$(YELLOW)Removing mypy cache...$(NC)"
@rm -rf .mypy_cache 2>/dev/null || true
@find . -type d -name ".mypy_cache" -exec rm -rf {} + 2>/dev/null || true
@echo "$(GREEN)✓ Mypy cache removed$(NC)"
clean-empty-dirs:
@echo "$(YELLOW)Removing empty directories...$(NC)"
@find . -type d -empty -not -path "./.git/*" -not -path "./.venv/*" -not -path "./venv/*" -not -path "./env/*" -not -path "./.env/*" -delete 2>/dev/null || true
@find . -type d -empty -not -path "./.git/*" -not -path "./.venv/*" -not -path "./venv/*" -not -path "./env/*" -not -path "./.env/*" -delete 2>/dev/null || true
@echo "$(GREEN)✓ Empty directories removed$(NC)"
clean-all: clean
@echo "$(YELLOW)Removing additional files...$(NC)"
@rm -rf htmlcov .coverage coverage.xml .coverage.* 2>/dev/null || true
@rm -rf build/ dist/ *.egg-info .eggs/ 2>/dev/null || true
@find . -type f -name "*.log" -delete 2>/dev/null || true
@find . -type d -name ".ipynb_checkpoints" -exec rm -rf {} + 2>/dev/null || true
@echo "$(GREEN)✓ Extended cleanup completed!$(NC)"
clean-dry-run:
@echo "$(YELLOW)Dry run - files that would be deleted (run 'make clean' to delete):$(NC)"
@find . -type d -name "__pycache__" 2>/dev/null || echo "None"
@find . -type f -name "*.pyc" 2>/dev/null || echo "None"
@find . -type d -name ".pytest_cache" 2>/dev/null || echo "None"
@find . -type d -name ".mypy_cache" 2>/dev/null || echo "None"