# CodePlay 开发指南 ## 项目结构 ``` CodePlay/ ├── CodePlay.Core/ # 核心转换引擎 ├── CodePlay.Persistence/ # 数据持久化层 ├── CodePlay.WebAPI/ # ASP.NET Core Web API ├── CodePlay.CLI/ # 命令行工具 ├── CodePlay.Web/ # Vue3 前端 ├── CodePlay.WebUI/ # Blazor 管理端 └── CodePlay.Tests/ # 单元测试 ``` ## 开发环境配置 ### 1. 安装 .NET 8.0 SDK https://dotnet.microsoft.com/download ### 2. 安装 Node.js 18+ https://nodejs.org/ ### 3. 克隆并还原依赖 ```bash git clone cd CodePlay dotnet restore ``` ### 4. 安装前端依赖 ```bash cd CodePlay.Web npm install ``` ## 构建和测试 ### 编译所有项目 ```bash dotnet build ``` ### 运行单元测试 ```bash dotnet test --logger "console;verbosity=normal" ``` ### 查看测试覆盖率 ```bash dotnet test /p:CollectCoverage=true ``` ### 代码格式化 ```bash dotnet format ``` ## 添加新功能 ### 1. 添加新的转换器 1. 在 `CodePlay.Core/Converters/` 创建新类 2. 实现 `IConverter` 接口 3. 在 `ConversionService` 中注册 ### 2. 添加新的 API 端点 1. 在 `CodePlay.WebAPI/Controllers/` 创建控制器 2. 添加 `[Authorize]` 特性 (如需认证) 3. 实现 CRUD 方法 ### 3. 添加前端组件 1. 在 `CodePlay.Web/src/components/` 创建组件 2. 在 `views/` 创建页面 3. 更新路由配置 ## 调试技巧 ### 日志查看 ```bash # 查看实时日志 tail -f logs/codeplay-*.log ``` ### API 测试 使用 Swagger UI: http://localhost:5000/swagger ### 前端调试 使用浏览器开发者工具的 Vue Devtools ## 提交代码 ```bash # 1. 确保测试通过 dotnet test # 2. 格式化代码 dotnet format # 3. 提交 git add . git commit -m "feat: description" git push ``` ## 发布 NuGet 包 ```bash # 1. 更新版本号 # 编辑 CodePlay.Core.csproj 中的 # 2. 打包 dotnet pack CodePlay.Core/CodePlay.Core.csproj -c Release # 3. 发布 dotnet nuget push CodePlay.Core.1.0.0.nupkg \ --source "https://api.nuget.org/v3/index.json" \ --api-key YOUR_API_KEY ``` ## Docker 部署 ```bash # 构建镜像 docker build -t codeplay:latest . # 运行 docker run -d -p 5000:80 codeplay:latest ```