feat: 跨平台发布打包,支持 7 个目标平台交叉编译和 tar.gz 分发
- 新增 scripts/release.ts,支持 7 个编译目标(linux/darwin/windows + musl 变体) - 从 build.ts 提取共享构建逻辑到 build-common.ts,现有 build 行为不变 - 使用 tar-stream + node:zlib 创建 tar.gz,精确控制 Unix 权限位 - SHA256 校验和文件格式兼容 sha256sum -c - 支持 --target 参数选择特定平台编译 - 新增 devDependency: tar-stream、@types/tar-stream - 更新 README.md 和 DEVELOPMENT.md 文档 - 同步 openspec specs
This commit is contained in:
@@ -950,7 +950,9 @@ bun run build
|
||||
|
||||
#### 构建流程
|
||||
|
||||
`scripts/build.ts` 执行三步流水线:
|
||||
构建逻辑拆分为两个文件:`scripts/build-common.ts`(共享函数)和 `scripts/build.ts`(编排逻辑)。
|
||||
|
||||
`scripts/build.ts` 执行三步流水线(函数来自 `build-common.ts`):
|
||||
|
||||
```
|
||||
1. Vite build → dist/web/ (前端静态资源,含 code splitting)
|
||||
@@ -992,10 +994,64 @@ bun run build
|
||||
|
||||
```bash
|
||||
bun run clean
|
||||
# 清理 dist/ 构建产物和 .build/ 临时文件
|
||||
# 清理 dist/ 构建产物、dist/release/ 发布产物和 .build/ 临时文件
|
||||
```
|
||||
|
||||
### 3.4 开发工作流
|
||||
### 3.4 跨平台发布
|
||||
|
||||
#### 发布命令
|
||||
|
||||
```bash
|
||||
bun run release # 编译全部 7 个目标平台
|
||||
bun run release --target linux-x64 # 编译指定平台
|
||||
bun run release --target linux-x64,windows-x64,darwin-arm64 # 多平台
|
||||
```
|
||||
|
||||
#### 发布流程
|
||||
|
||||
`scripts/release.ts` 复用 `build-common.ts` 的前端构建和代码生成,然后执行多目标交叉编译和打包:
|
||||
|
||||
```
|
||||
1. Vite build → dist/web/ (前端静态资源,只执行一次)
|
||||
2. Code generation → .build/ (资源嵌入代码)
|
||||
3. 多目标 Bun compile → dist/release/binaries/ (7 个目标平台二进制)
|
||||
4. tar.gz 打包 → dist/release/packages/ (压缩包 + SHA256 校验和)
|
||||
```
|
||||
|
||||
#### 支持的目标平台
|
||||
|
||||
| CLI 参数 | Bun CompileTarget | 说明 |
|
||||
| ------------------ | ---------------------- | ------------------- |
|
||||
| `linux-x64` | `bun-linux-x64` | Linux x64 glibc |
|
||||
| `linux-arm64` | `bun-linux-arm64` | Linux ARM64 glibc |
|
||||
| `linux-x64-musl` | `bun-linux-x64-musl` | Linux x64 musl |
|
||||
| `linux-arm64-musl` | `bun-linux-arm64-musl` | Linux ARM64 musl |
|
||||
| `windows-x64` | `bun-windows-x64` | Windows x64 |
|
||||
| `darwin-x64` | `bun-darwin-x64` | macOS Intel |
|
||||
| `darwin-arm64` | `bun-darwin-arm64` | macOS Apple Silicon |
|
||||
|
||||
#### 产出物
|
||||
|
||||
```
|
||||
dist/release/
|
||||
├── binaries/ ← 裸二进制
|
||||
│ ├── dial-server-{version}-{os}-{arch}[.exe]
|
||||
│ └── ...
|
||||
└── packages/ ← 压缩包 + 校验和
|
||||
├── dial-server_{version}_{os}_{arch}.tar.gz
|
||||
├── dial-server_{version}_{os}_{arch}.tar.gz.sha256
|
||||
└── ...
|
||||
```
|
||||
|
||||
压缩包内含可执行文件(`dial-server` 或 `dial-server.exe`)、`probes.example.yaml` 和 `LICENSE`。
|
||||
|
||||
#### 命名规范
|
||||
|
||||
- 裸二进制:`dial-server-{version}-{os}-{arch}[.exe]`,如 `dial-server-0.1.0-linux-x64`
|
||||
- 压缩包:`dial-server_{version}_{os}_{arch}.tar.gz`,如 `dial-server_0.1.0_linux_x64.tar.gz`
|
||||
- 校验和:`<压缩包文件名>.sha256`,格式兼容 `sha256sum -c`
|
||||
|
||||
### 3.5 开发工作流
|
||||
|
||||
#### 日常开发循环
|
||||
|
||||
@@ -1015,29 +1071,30 @@ bun run verify
|
||||
|
||||
`verify` 适合 CI 或正式提交前,会完整验证类型检查、lint、格式、单元测试和生产构建。
|
||||
|
||||
### 3.5 Executable/E2E 验证
|
||||
### 3.6 Executable/E2E 验证
|
||||
|
||||
原 `scripts/smoke.ts` 覆盖过薄,已从当前工作流移除。后续如需验证 production executable 的 API、静态资源服务、SPA fallback 行为,应重新设计独立的 executable/E2E 测试。
|
||||
|
||||
### 3.6 脚本说明
|
||||
### 3.7 脚本说明
|
||||
|
||||
| 脚本 | 文件 | 说明 |
|
||||
| ---------------------- | ----------------------------------- | ---------------------------------------- |
|
||||
| `bun run dev` | `scripts/dev.ts` | 双进程开发服务(Vite :5173 + API :3000) |
|
||||
| `bun run dev:server` | `src/server/dev.ts` | 仅启动后端 API server |
|
||||
| `bun run dev:web` | Vite CLI | 仅启动 Vite dev server |
|
||||
| `bun run build` | `scripts/build.ts` | Vite → codegen → Bun compile 三步构建 |
|
||||
| `bun run schema` | `scripts/generate-config-schema.ts` | 生成 `probe-config.schema.json` |
|
||||
| `bun run schema:check` | `scripts/generate-config-schema.ts` | 检查配置 schema 导出物是否同步 |
|
||||
| `bun run clean` | `scripts/clean.ts` | 清理构建缓存与临时文件 |
|
||||
| 脚本 | 文件 | 说明 |
|
||||
| ---------------------- | ----------------------------------- | -------------------------------------------------- |
|
||||
| `bun run dev` | `scripts/dev.ts` | 双进程开发服务(Vite :5173 + API :3000) |
|
||||
| `bun run dev:server` | `src/server/dev.ts` | 仅启动后端 API server |
|
||||
| `bun run dev:web` | Vite CLI | 仅启动 Vite dev server |
|
||||
| `bun run build` | `scripts/build.ts` | Vite → codegen → Bun compile 三步构建 |
|
||||
| `bun run release` | `scripts/release.ts` | 跨平台发布打包(多目标交叉编译 + tar.gz + SHA256) |
|
||||
| `bun run schema` | `scripts/generate-config-schema.ts` | 生成 `probe-config.schema.json` |
|
||||
| `bun run schema:check` | `scripts/generate-config-schema.ts` | 检查配置 schema 导出物是否同步 |
|
||||
| `bun run clean` | `scripts/clean.ts` | 清理构建缓存与临时文件 |
|
||||
|
||||
### 3.7 环境变量
|
||||
### 3.8 环境变量
|
||||
|
||||
| 变量 | 用途 | 默认值 |
|
||||
| --------------------------- | ----------------------------------------------- | -------- |
|
||||
| `BUN_TARGET`/`BUILD_TARGET` | 交叉编译目标平台(仅在 `bun run build` 时有效) | 当前平台 |
|
||||
|
||||
### 3.8 项目配置文件
|
||||
### 3.9 项目配置文件
|
||||
|
||||
| 文件 | 用途 |
|
||||
| ---------------------- | ---------------------------------------------- |
|
||||
@@ -1050,14 +1107,14 @@ bun run verify
|
||||
| `probes.example.yaml` | 配置文件示例 |
|
||||
| `opencode.json` | OpenCode 工具配置(TDesign MCP server) |
|
||||
|
||||
### 3.9 依赖管理
|
||||
### 3.10 依赖管理
|
||||
|
||||
- **包管理器**:仅使用 `bun`,禁止使用 npm、pnpm、yarn
|
||||
- **安装依赖**:`bun install`
|
||||
- **运行工具**:使用 `bunx`,禁止使用 `npx`、`pnpx`
|
||||
- **锁文件**:`bun.lock`
|
||||
|
||||
### 3.10 目录约定
|
||||
### 3.11 目录约定
|
||||
|
||||
| 目录 | 约定 |
|
||||
| ------------- | ---------------------------------------------------- |
|
||||
|
||||
Reference in New Issue
Block a user