本文档介绍如何参与 MeshKit 项目的开发。
- Node.js >= 18.0.0
- pnpm >= 8.0.0
- Git >= 2.30
- VS Code - 代码编辑器
- TypeScript extension - TS 语言支持
- ESLint extension - 代码检查
- Prettier extension - 代码格式化
# 使用 HTTPS
git clone https://github.com/cainiaopppppppp/MeshKit.git
# 或使用 SSH
git clone git@github.com:cainiaopppppppp/MeshKit.git
cd MeshKitpnpm installpnpm --filter @meshkit/core build# 方式一:同时启动所有服务
pnpm dev
# 方式二:分别启动
pnpm dev:signaling # 终端1
pnpm dev:web # 终端2MeshKit/
├── packages/
│ ├── core/ # 核心业务逻辑
│ │ ├── src/
│ │ │ ├── managers/ # 管理器
│ │ │ ├── types/ # 类型定义
│ │ │ ├── utils/ # 工具函数
│ │ │ └── index.ts # 导出入口
│ │ ├── package.json
│ │ ├── tsconfig.json
│ │ └── tsup.config.ts # 构建配置
│ │
│ ├── web/ # Web 应用
│ │ ├── src/
│ │ │ ├── components/ # React 组件
│ │ │ ├── pages/ # 页面组件
│ │ │ ├── hooks/ # React Hooks
│ │ │ ├── store/ # Zustand 状态管理
│ │ │ ├── utils/ # 工具函数
│ │ │ ├── App.tsx # 根组件
│ │ │ └── main.tsx # 入口文件
│ │ ├── public/ # 静态资源
│ │ ├── package.json
│ │ ├── vite.config.ts # Vite 配置
│ │ └── tailwind.config.js # Tailwind 配置
│ │
│ └── desktop/ # Desktop 应用
│ ├── src/
│ │ ├── main/ # Electron 主进程
│ │ ├── preload/ # 预加载脚本
│ │ └── renderer/ # 渲染进程 (React)
│ ├── build/ # 构建资源 (图标等)
│ └── package.json
│
├── apps/
│ └── signaling/ # 信令服务器
│ ├── src/
│ │ └── index.ts # 服务器入口
│ └── package.json
│
├── docs/ # 文档
├── turbo.json # Turborepo 配置
├── pnpm-workspace.yaml # pnpm 工作空间
└── package.json # 根配置
- 创建功能分支
git checkout -b feature/your-feature-name- 编写代码
- 遵循现有代码风格
- 添加必要的注释
- 编写类型定义
- 测试功能
- 在浏览器中测试
- 测试多设备场景
- 测试边界条件
- 提交代码
git add .
git commit -m "feat: your feature description"- 推送并创建 PR
git push origin feature/your-feature-name- 创建修复分支
git checkout -b fix/bug-description- 定位问题
- 查看控制台错误
- 使用 Chrome DevTools 调试
- 检查网络请求
- 修复并测试
- 修复问题
- 确保不引入新问题
- 添加回归测试
- 提交
git commit -m "fix: bug description"// 好的示例
interface User {
id: string;
name: string;
email?: string;
}
function getUserName(user: User): string {
return user.name;
}
// 避免
function getUserName(user: any) { // 不要使用 any
return user.name;
}// 好的示例
interface Props {
title: string;
onClose: () => void;
}
export function Modal({ title, onClose }: Props) {
return (
<div>
<h1>{title}</h1>
<button onClick={onClose}>Close</button>
</div>
);
}
// 避免
export function Modal(props: any) { // 不明确的 props
return <div>{props.title}</div>;
}-
文件名: PascalCase for components, camelCase for utils
-
FileTransferPage.tsx -
useP2P.ts -
formatBytes.ts -
变量名: camelCase
-
deviceId -
isConnected -
常量: UPPER_SNAKE_CASE
-
MAX_FILE_SIZE -
DEFAULT_TIMEOUT -
类型/接口: PascalCase
-
interface Device {} -
type MessageType = 'text' | 'file'
<type>(<scope>): <description>
[optional body]
[optional footer]
类型 (type):
feat: 新功能fix: Bug 修复docs: 文档更新style: 代码格式(不影响功能)refactor: 重构perf: 性能优化test: 测试相关chore: 构建/工具配置
示例:
feat(file-transfer): add resume capability
fix(chat): correct message order
docs: update installation guide
- Chrome DevTools
// 在代码中添加断点
debugger;
// 查看 WebRTC 连接
chrome://webrtc-internals- 查看日志
// Core 包日志
console.log('[P2PManager]', ...);
console.log('[FileTransfer]', ...);- 网络请求
- 打开 Network 标签
- 查看 WebSocket 连接
- 检查 WebRTC 数据通道
# 启动时开启调试
pnpm dev:electron
# 主进程日志会显示在终端
# 渲染进程可使用 Chrome DevTools- Core 包未更新
# 重新构建 Core 包
pnpm --filter @meshkit/core build- 端口被占用
# 查找占用端口的进程
lsof -i :3000 # Mac/Linux
netstat -ano | findstr :3000 # Windows
# 杀死进程或更改端口- TypeScript 错误
# 类型检查
pnpm type-check
# 清除缓存
rm -rf node_modules/.cache- 文件传输测试
- 小文件 (<1MB)
- 大文件 (>1GB)
- 多文件批量传输
- 不同文件类型
- 便签墙测试
- 创建/编辑/删除便签
- 多设备同步
- 离线后上线同步
- 加密聊天测试
- 发送/接收消息
- 连接建立/断开
- 密钥交换
- Chrome/Edge
- Firefox
- Safari
- Mobile Safari
- Mobile Chrome
// 调整 chunk 大小
const CHUNK_SIZE = 1024 * 1024; // 1MB
// 调整发送延迟
const SEND_DELAY = 1; // ms// 减少重新渲染
const MemoizedNote = React.memo(Note);
// 虚拟化大列表 (如有大量便签)
import { FixedSizeList } from 'react-window';// 复用加密上下文
const cryptoContext = useMemo(() => {
return sodium.crypto_box_beforenm(peerPublicKey, secretKey);
}, [peerPublicKey, secretKey]);提交 PR 前,请确保:
- 代码遵循项目规范
- 添加了必要的类型定义
- 功能在多个浏览器中测试
- 没有 TypeScript 错误
- 没有 ESLint 警告
- Commit 信息符合规范
- 更新了相关文档
- 测试了边界条件
遇到问题?
- 查看 文档
- 提交 Issue
- 参与 Discussions
感谢你的贡献!