Skip to content

Commit 12d6041

Browse files
committed
Add build automation scripts and test infrastructure improvements
Adds PowerShell build script (build.ps1) for Windows with cross-platform Makefile enhancements. Both scripts provide unified commands for dependency installation, testing, linting, formatting, and Docker operations with automatic prerequisite checks. Makefile improvements: - Dependency detection for Node.js, npm, and .NET CLI - New targets: install, test, lint, format, check-deps - Enhanced error messages for missing dependencies - Docker
1 parent dd694d0 commit 12d6041

File tree

24 files changed

+736
-34
lines changed

24 files changed

+736
-34
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
130130
<PackageVersion Include="FsCheck" Version="3.3.2" />
131131
<PackageVersion Include="FsCheck.Xunit" Version="3.3.2" />
132+
<PackageVersion Include="Moq" Version="4.20.72" />
132133
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
133134
<PackageVersion Include="BCrypt.Net-Next" Version="4.0.3" />
134135
</ItemGroup>

Makefile

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# 检测是否支持 docker compose
22
DOCKER_COMPOSE := $(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)
33

4-
.PHONY: all build build-backend build-frontend build-docs build-arm build-amd build-backend-arm build-backend-amd up down restart dev dev-backend dev-web logs clean help
4+
# 检测 Node.js 和 npm
5+
NODE_EXISTS := $(shell if node --version >/dev/null 2>&1; then echo "true"; else echo "false"; fi)
6+
NPM_EXISTS := $(shell if npm --version >/dev/null 2>&1; then echo "true"; else echo "false"; fi)
7+
8+
# 检测 .NET CLI
9+
DOTNET_EXISTS := $(shell if dotnet --version >/dev/null 2>&1; then echo "true"; else echo "false"; fi)
10+
11+
.PHONY: all build build-backend build-frontend build-docs build-arm build-amd build-backend-arm build-backend-amd up down restart dev dev-backend dev-web logs clean help test test-backend test-frontend lint lint-frontend format format-backend install install-frontend install-backend check-deps
512

613
all: build up
714

@@ -16,12 +23,22 @@ build-backend:
1623
# 构建前端项目
1724
build-frontend:
1825
@echo "Building frontend..."
26+
@if [ "$(NODE_EXISTS)" = "false" ] || [ "$(NPM_EXISTS)" = "false" ]; then \
27+
echo "错误: Node.js 或 npm 未安装,请先安装 Node.js"; \
28+
exit 1; \
29+
fi
1930
cd web && npm install && npm run build
31+
@echo "Frontend build completed!"
2032

2133
# 构建文档站
2234
build-docs:
2335
@echo "Building docs..."
36+
@if [ "$(NODE_EXISTS)" = "false" ] || [ "$(NPM_EXISTS)" = "false" ]; then \
37+
echo "错误: Node.js 或 npm 未安装,请先安装 Node.js"; \
38+
exit 1; \
39+
fi
2440
cd docs && npm install && npm run build
41+
@echo "Docs build completed!"
2542

2643
# 构建ARM架构的所有Docker镜像
2744
build-arm:
@@ -69,6 +86,86 @@ logs:
6986
# 清理所有Docker资源(慎用)
7087
clean:
7188
$(DOCKER_COMPOSE) down --rmi all --volumes --remove-orphans
89+
docker system prune -f
90+
91+
# 安装依赖
92+
install: install-frontend install-backend
93+
94+
# 安装前端依赖
95+
install-frontend:
96+
@echo "Installing frontend dependencies..."
97+
@if [ "$(NODE_EXISTS)" = "false" ] || [ "$(NPM_EXISTS)" = "false" ]; then \
98+
echo "错误: Node.js 或 npm 未安装,请先安装 Node.js"; \
99+
exit 1; \
100+
fi
101+
cd web && npm install
102+
cd docs && npm install
103+
@echo "Frontend dependencies installed!"
104+
105+
# 安装后端依赖
106+
install-backend:
107+
@echo "Installing backend dependencies..."
108+
@if [ "$(DOTNET_EXISTS)" = "false" ]; then \
109+
echo "错误: .NET CLI 未安装,请先安装 .NET SDK"; \
110+
exit 1; \
111+
fi
112+
dotnet restore OpenDeepWiki.sln
113+
@echo "Backend dependencies restored!"
114+
115+
# 运行测试
116+
test: test-backend test-frontend
117+
118+
# 运行后端测试
119+
test-backend:
120+
@echo "Running backend tests..."
121+
@if [ "$(DOTNET_EXISTS)" = "false" ]; then \
122+
echo "错误: .NET CLI 未安装,请先安装 .NET SDK"; \
123+
exit 1; \
124+
fi
125+
dotnet test tests/OpenDeepWiki.Tests/OpenDeepWiki.Tests.csproj --logger "console;verbosity=detailed"
126+
127+
# 运行前端测试
128+
test-frontend:
129+
@echo "Running frontend tests..."
130+
@if [ "$(NODE_EXISTS)" = "false" ] || [ "$(NPM_EXISTS)" = "false" ]; then \
131+
echo "错误: Node.js 或 npm 未安装,请先安装 Node.js"; \
132+
exit 1; \
133+
fi
134+
cd web && npm test
135+
136+
# 代码检查
137+
lint: lint-frontend
138+
139+
# 前端代码检查
140+
lint-frontend:
141+
@echo "Running frontend linting..."
142+
@if [ "$(NODE_EXISTS)" = "false" ] || [ "$(NPM_EXISTS)" = "false" ]; then \
143+
echo "错误: Node.js 或 npm 未安装,请先安装 Node.js"; \
144+
exit 1; \
145+
fi
146+
cd web && npm run lint
147+
cd docs && npm run lint
148+
149+
# 代码格式化
150+
format: format-backend
151+
152+
# 后端代码格式化
153+
format-backend:
154+
@echo "Formatting backend code..."
155+
@if [ "$(DOTNET_EXISTS)" = "false" ]; then \
156+
echo "错误: .NET CLI 未安装,请先安装 .NET SDK"; \
157+
exit 1; \
158+
fi
159+
dotnet format OpenDeepWiki.sln
160+
161+
# 检查依赖
162+
check-deps:
163+
@echo "Checking dependencies..."
164+
@echo "Node.js: $$(node --version 2>/dev/null || echo 'Not installed')"
165+
@echo "npm: $$(npm --version 2>/dev/null || echo 'Not installed')"
166+
@echo ".NET: $$(dotnet --version 2>/dev/null || echo 'Not installed')"
167+
@echo "Docker: $$(docker --version 2>/dev/null || echo 'Not installed')"
168+
@echo "Docker Compose: $$($(DOCKER_COMPOSE) version 2>/dev/null || echo 'Not available')"
72169

73170
# 显示帮助信息
74171
help:
@@ -89,6 +186,17 @@ help:
89186
@echo " make dev-web - 只启动前端开发环境"
90187
@echo " make logs - 查看服务日志"
91188
@echo " make clean - 清理所有Docker资源(慎用)"
189+
@echo " make install - 安装所有依赖"
190+
@echo " make install-frontend - 安装前端依赖"
191+
@echo " make install-backend - 安装后端依赖"
192+
@echo " make test - 运行所有测试"
193+
@echo " make test-backend - 运行后端测试"
194+
@echo " make test-frontend - 运行前端测试"
195+
@echo " make lint - 运行代码检查"
196+
@echo " make lint-frontend - 运行前端代码检查"
197+
@echo " make format - 格式化代码"
198+
@echo " make format-backend - 格式化后端代码"
199+
@echo " make check-deps - 检查系统依赖"
92200
@echo " make help - 显示此帮助信息"
93201

94202
# 默认目标

0 commit comments

Comments
 (0)