Thank you for your interest in contributing to cocos-cli! This guide will help you get started with development, testing, and submitting changes.
Before you begin, ensure you have:
- Node.js >= 16.x
- npm >= 8.x
- Git
- Fork and Clone
git clone https://github.com/YOUR_USERNAME/cocos-cli.git
cd cocos-cli- Install Dependencies
npm install- Build the Project
npm run buildThis will:
- Clear previous build artifacts
- Compile TypeScript to JavaScript
- Copy
.d.tsdeclaration files - Generate JSON schemas
Full Build (recommended for first build or after major changes):
npm run build
# or
npm run compileWatch Mode (for active development):
npm run build:watchThis will automatically recompile TypeScript files when you make changes.
Clear Build Cache:
npm run build:clearAfter modifying MCP API schemas or tools:
npm run generate:mcp-typesThis generates type-safe definitions for E2E tests in e2e/types/mcp-tools.generated.ts.
Run all unit tests:
npm testRun tests in watch mode (for active development):
npm run test:watchRun tests with coverage report:
npm run test:coverageRun tests silently (minimal output):
npm run test:quietFull E2E test suite:
npm run test:e2eE2E tests with debug mode (preserves test workspace):
npm run test:e2e:debugThe test workspace will be preserved at .test-workspace for inspection.
Check E2E test coverage:
# Console output
npm run check:e2e-coverage
# Generate HTML report
npm run check:e2e-coverage:reportThe coverage report will be saved to e2e/server/reports/.
npm run test:allThis runs both unit tests and E2E tests.
This project uses ESLint and Prettier for code formatting.
Check for linting errors:
# Check specific files
npx eslint src/**/*.ts
# Check all TypeScript files
npx tsc --noEmitAuto-fix formatting (if configured):
npx eslint --fix src/**/*.tsStart the MCP server with a test project:
npm run start:mcp-debugThis starts the MCP server using the test project at ./tests/fixtures/projects/asset-operation.
Use the MCP Inspector to interact with the server:
npm run start:mcp-inspectorThis opens a web interface for testing MCP tools.
Method 1: Preserve Test Workspace
npm run test:e2e:debugThe test workspace will be kept after tests finish, allowing you to inspect the state.
Method 2: Debug in VS Code
Add this configuration to .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug E2E Tests",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "test:e2e", "--", "--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"runtimeExecutable": "npm",
"runtimeArgs": ["test", "--", "--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}Method 3: Debug Specific Test File
npx jest path/to/test.test.ts --runInBandnode --inspect-brk ./dist/cli.js [command] [options]Then attach your debugger to the Node.js process.
git checkout -b feature/your-feature-name- Write clear, concise commit messages
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
# Run all tests
npm run test:all
# Check E2E coverage if you modified APIs
npm run check:e2e-coverage:reportgit add .
git commit -m "feat: add new feature"
git push origin feature/your-feature-name- Go to the repository on GitHub
- Click "New Pull Request"
- Fill in the PR template with:
- Description of changes
- Related issues
- Test results
- Screenshots (if UI changes)
Follow Conventional Commits:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changes (formatting, etc.)refactor:Code refactoringtest:Adding or updating testschore:Maintenance tasks
Examples:
feat: add assets-create-asset MCP tool
fix: resolve null reference in asset query
docs: update E2E testing guide
test: add E2E tests for builder API
- E2E Testing Guide: See
e2e/README.md - Type Inference Guide: See
e2e/docs/TYPE-INFERENCE-EXAMPLE.md - Test Coverage Report: See
e2e/scripts/README.md
感谢您对 cocos-cli 项目的关注!本指南将帮助您开始开发、测试和提交代码变更。
开始之前,请确保安装:
- Node.js >= 16.x
- npm >= 8.x
- Git
- Fork 并克隆仓库
git clone https://github.com/YOUR_USERNAME/cocos-cli.git
cd cocos-cli- 安装依赖
npm install- 构建项目
npm run build这将:
- 清理之前的构建产物
- 编译 TypeScript 到 JavaScript
- 复制
.d.ts类型声明文件 - 生成 JSON schemas
完整构建(推荐用于首次构建或重大更改后):
npm run build
# 或
npm run compile监听模式(用于活跃开发):
npm run build:watch这会在你修改文件时自动重新编译 TypeScript 文件。
清理构建缓存:
npm run build:clear修改 MCP API schemas 或工具后:
npm run generate:mcp-types这会在 e2e/types/mcp-tools.generated.ts 中生成 E2E 测试的类型安全定义。
运行所有单元测试:
npm test监听模式运行测试(用于活跃开发):
npm run test:watch运行测试并生成覆盖率报告:
npm run test:coverage静默运行测试(最小输出):
npm run test:quiet完整 E2E 测试套件:
npm run test:e2eE2E 测试调试模式(保留测试工作区):
npm run test:e2e:debug测试工作区将保留在 .test-workspace 目录中以供检查。
检查 E2E 测试覆盖率:
# 控制台输出
npm run check:e2e-coverage
# 生成 HTML 报告
npm run check:e2e-coverage:report覆盖率报告将保存到 e2e/server/reports/ 目录。
npm run test:all这会同时运行单元测试和 E2E 测试。
本项目使用 ESLint 和 Prettier 进行代码格式化。
检查 lint 错误:
# 检查特定文件
npx eslint src/**/*.ts
# 检查所有 TypeScript 文件
npx tsc --noEmit自动修复格式(如果已配置):
npx eslint --fix src/**/*.ts使用测试项目启动 MCP 服务器:
npm run start:mcp-debug这会使用 ./tests/fixtures/projects/asset-operation 测试项目启动 MCP 服务器。
使用 MCP Inspector 与服务器交互:
npm run start:mcp-inspector这会打开一个 Web 界面用于测试 MCP 工具。
方法 1:保留测试工作区
npm run test:e2e:debug测试完成后将保留工作区,允许你检查状态。
方法 2:在 VS Code 中调试
在 .vscode/launch.json 中添加以下配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "调试 E2E 测试",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "test:e2e", "--", "--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "调试单元测试",
"runtimeExecutable": "npm",
"runtimeArgs": ["test", "--", "--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}方法 3:调试特定测试文件
npx jest path/to/test.test.ts --runInBandnode --inspect-brk ./dist/cli.js [command] [options]然后将调试器附加到 Node.js 进程。
git checkout -b feature/your-feature-name- 编写清晰、简洁的提交信息
- 遵循现有代码风格
- 为新功能添加测试
- 根据需要更新文档
# 运行所有测试
npm run test:all
# 如果修改了 API,检查 E2E 覆盖率
npm run check:e2e-coverage:reportgit add .
git commit -m "feat: 添加新功能"
git push origin feature/your-feature-name- 前往 GitHub 上的仓库
- 点击 "New Pull Request"
- 在 PR 模板中填写:
- 变更描述
- 相关 issues
- 测试结果
- 截图(如果有 UI 变更)
feat:新功能fix:Bug 修复docs:文档变更style:代码风格变更(格式化等)refactor:代码重构test:添加或更新测试chore:维护任务
示例:
feat: 添加 assets-create-asset MCP 工具
fix: 修复资源查询中的空引用问题
docs: 更新 E2E 测试指南
test: 添加构建器 API 的 E2E 测试
- E2E 测试指南:查看
e2e/README.md - 类型推断指南:查看
e2e/docs/TYPE-INFERENCE-EXAMPLE.md - 测试覆盖率报告:查看
e2e/scripts/README.md
If you have questions or need help:
- Open an issue on GitHub
- Check existing documentation in the
docs/directory - Review E2E testing guides in
e2e/docs/
如果您有问题或需要帮助:
- 在 GitHub 上提出 issue
- 查看
docs/目录中的现有文档 - 查看
e2e/docs/中的 E2E 测试指南