开发指南
欢迎参与 biliLive-tools 的开发!本指南将帮助你快速开始。
技术栈
- 桌面程序:Electron + Vue 3 + TypeScript + Vite
- CLI:Node.js + TypeScript
- 后端:Node.js + Express + TypeScript
- 前端:Vue 3 + TypeScript + Vite
- 数据库:SQLite (better-sqlite3)
- 视频处理:FFmpeg
- 弹幕处理:DanmakuFactory
开发环境
Node.js 版本
根据 .node-version 文件选择 Node.js 版本。
包管理器
项目使用 pnpm 作为包管理器,具体版本参考 package.json 中的相关字段。
安装 pnpm:
bash
npm install -g pnpm@9.15.2克隆仓库
bash
git clone https://github.com/renmu123/biliLive-tools.git
cd biliLive-tools安装依赖
bash
pnpm install
pnpm run install:bin关于 better-sqlite3
如果 better-sqlite3 无法安装:
- 安装 Visual Studio 2022 中的 C++ 工具
- 安装 Python 3
- 如果还是无法安装,运行:bash
node scripts\github-ci-better-sqlite3.js
详见 Issue #5638
如果你是Win,你还可能遇到报错比如cause=fork/exec %1 is not a valid Win32 application.,根据提示修改pnpm源文件。
关于二进制依赖
二进制依赖下载完成后,需要手动去设置中配置对应的可执行文件路径
如果二进制依赖安装失败或不支持你的平台,请手动下载,版本选择最靠近当前版本的版本。
创建 packages\app\resources\bin 目录,放入以下文件:
同时需要在应用设置中配置可执行文件路径。
项目结构
biliLive-tools/
├── packages/
│ ├── app/ # Electron 桌面应用
│ │ ├── src/
│ │ │ ├── main/ # 主进程
│ │ │ ├── preload/ # 预加载脚本
│ │ │ └── renderer/ # 渲染进程(Vue)
│ │ └── resources/ # 资源文件
│ ├── CLI/ # 命令行工具
│ ├── http/ # HTTP 服务
│ ├── shared/ # 核心代码
│ ├── types/ # 类型定义
│ ├── BilibiliRecorder/ # B站录制
│ ├── DouYinRecorder/ # 抖音录制
│ ├── DouYuRecorder/ # 斗鱼录制
│ ├── HuYaRecorder/ # 虎牙录制
│ ├── liveManager/ # 直播管理
│ └── ...
├── docs/ # 文档
├── docker/ # Docker 配置
└── scripts/ # 脚本开发命令
桌面应用开发
bash
# 启动开发服务器
pnpm run dev
# 构建应用
pnpm run build:appCLI 开发
bash
# 构建 CLI
pnpm run build:cli
# 本地测试
cd packages/CLI
npm link
bililive-cli --help运行测试
bash
# 运行所有测试
pnpm run test
# 运行特定包的测试
cd packages/shared
pnpm run test代码规范
TypeScript
项目使用 TypeScript,请确保:
- 所有新代码都使用 TypeScript
- 遵循已有的类型定义风格
- 不使用
any,除非必要
代码风格
项目使用 ESLint 和 Prettier:
bash
# 检查代码风格
pnpm run lint
# 自动修复
pnpm run lint:fix
# 格式化代码
pnpm run format提交规范
使用 Conventional Commits 规范:
feat: 添加新功能
fix: 修复bug
docs: 文档更新
style: 代码风格修改
refactor: 代码重构
test: 测试相关
chore: 构建/工具相关示例:
feat: 支持抖音直播录制
fix: 修复上传失败的问题
docs: 更新安装文档开发流程
1. 创建分支
bash
git checkout -b feature/your-feature
# 或
git checkout -b fix/your-fix2. 开发功能
- 编写代码
- 添加测试
- 更新文档
3. 测试
bash
# 运行测试
pnpm run test
# 本地测试应用
pnpm run dev4. 提交代码
bash
git add .
git commit -m "feat: your feature description"5. 推送分支
bash
git push origin feature/your-feature6. 创建 Pull Request
在 GitHub 上创建 Pull Request。
测试
单元测试
使用 Vitest:
typescript
import { describe, it, expect } from "vitest";
describe("MyFunction", () => {
it("should work correctly", () => {
expect(myFunction()).toBe("expected");
});
});集成测试
typescript
describe("Integration Test", () => {
it("should integrate correctly", async () => {
const result = await integrateFunction();
expect(result).toBeDefined();
});
});运行测试
bash
# 运行所有测试
pnpm run test
# 运行特定文件
pnpm run test path/to/test.spec.ts
# 监听模式
pnpm run test:watch
# 覆盖率
pnpm run test:coverage构建
桌面应用构建
bash
# 构建所有平台
pnpm run build:app
# 只构建 Windows
pnpm run build:app:win
# 只构建 Linux
pnpm run build:app:linux
# 只构建 Mac
pnpm run build:app:macDocker 构建
bash
# 构建前端
docker build -f docker/frontend-dockerfile -t bililive-tools-frontend .
# 构建后端
docker build -f docker/backend-dockerfile -t bililive-tools-backend .发布
发布流程:
- 更新版本号(
package.json) - 更新 CHANGELOG.md
- 提交更改
- 创建 Tag
- 推送到 GitHub
- GitHub Actions 自动构建和发布
bash
# 更新版本
npm version patch # 或 minor, major
# 推送
git push origin master --tags常见问题
依赖安装失败
- 清理缓存:
pnpm store prune - 删除 node_modules:
rm -rf node_modules - 重新安装:
pnpm install
编译错误
- 检查 TypeScript 版本
- 检查 Node.js 版本
- 清理构建缓存
- 重新构建
运行时错误
- 检查日志文件
- 使用调试模式
- 查看浏览器控制台
相关资源
文档
社区
贡献指南
参考 贡献指南 了解如何贡献代码。
