# 构建与发布脚本 本目录包含 Claude AI Installer 的构建和发布脚本。 ## 两种使用方式 ### 1. 只构建,不发布 ```bash npm run build:win # 仅构建 Windows npm run build:mac # 仅构建 macOS npm run build:linux # 仅构建 Linux npm run build:all # 构建所有平台 ``` 只生成安装包到 `release/` 目录,不修改版本号,不创建 Git tag。 ### 2. 发布(包含构建) ```bash npm run release:patch # 更新版本 → 构建 → 创建 tag npm run release:minor # 次版本发布 npm run release:major # 主版本发布 ``` 完整流程:更新版本号 → 构建所有平台 → 生成发布说明 → 创建 Git tag。 **简单来说:** - `build.js` = 单纯构建 - `release.js` = 更新版本 + 构建 + 发布相关操作 --- ## 快速开始 ```bash # 进入项目目录 cd ApqInstaller # 安装依赖 npm install # 构建当前平台 npm run build:win # Windows npm run build:mac # macOS npm run build:linux # Linux npm run build:all # 所有平台 ``` ## 脚本说明 ### build.js - 构建脚本 多平台构建脚本,用于编译和打包应用。 #### 用法 ```bash node scripts/build.js [选项] ``` #### 选项 | 选项 | 简写 | 说明 | 默认值 | |------|------|------|--------| | `--platform` | `-p` | 目标平台: `win`, `mac`, `linux`, `all` | 当前平台 | | `--arch` | `-a` | 目标架构: `x64`, `arm64`, `all` | 当前架构 | | `--publish` | `-P` | 发布模式: `always`, `onTag`, `never` | `never` | | `--skip-build` | - | 跳过前端构建,仅打包 | - | | `--help` | `-h` | 显示帮助信息 | - | #### 示例 ```bash # 构建 Windows 版本 node scripts/build.js -p win # 构建 macOS ARM64 版本 node scripts/build.js -p mac -a arm64 # 构建所有平台 node scripts/build.js -p all # 跳过前端构建,仅打包 node scripts/build.js -p win --skip-build ``` --- ### release.js - 发布脚本 自动化发布脚本,按以下顺序执行: 1. 更新版本号(可选) 2. 构建所有平台安装包 3. 生成发布说明 4. 创建 Git tag(可选) 5. 推送到远程(可选) #### 用法 ```bash node scripts/release.js [版本] [选项] ``` #### 版本参数 | 参数 | 说明 | 示例 | |------|------|------| | `patch` | 补丁版本 +1 | 0.0.1 → 0.0.2 | | `minor` | 次版本 +1 | 0.0.1 → 0.1.0 | | `major` | 主版本 +1 | 0.0.1 → 1.0.0 | | `x.y.z` | 指定版本号 | 1.2.3 | #### 选项 | 选项 | 简写 | 说明 | |------|------|------| | `--tag` | `-t` | 创建 Git tag | | `--push` | - | 推送 tag 到远程仓库 | | `--platform` | `-p` | 指定平台 (逗号分隔) | | `--dry-run` | - | 仅显示操作,不实际执行 | | `--help` | `-h` | 显示帮助信息 | #### 示例 ```bash # 更新补丁版本并构建 node scripts/release.js patch # 设置版本为 1.0.0 并创建 tag node scripts/release.js 1.0.0 --tag # 更新次版本,仅构建 Windows 和 macOS node scripts/release.js minor -p win,mac # 完整发布流程:更新版本、构建、创建 tag、推送 node scripts/release.js patch --tag --push # 预览发布操作(不实际执行) node scripts/release.js patch --dry-run ``` --- ## NPM Scripts 在 `package.json` 中预定义了以下命令: ### 构建命令 | 命令 | 说明 | |------|------| | `npm run build:win` | 构建 Windows 版本 | | `npm run build:mac` | 构建 macOS 版本 | | `npm run build:linux` | 构建 Linux 版本 | | `npm run build:all` | 构建所有平台 | ### 发布命令 | 命令 | 说明 | |------|------| | `npm run release` | 发布(不更新版本) | | `npm run release:patch` | 发布补丁版本 + 创建 tag | | `npm run release:minor` | 发布次版本 + 创建 tag | | `npm run release:major` | 发布主版本 + 创建 tag | --- ## 构建产物 构建完成后,安装包会输出到 `release/` 目录: ### Windows | 格式 | 文件名 | 说明 | |------|--------|------| | NSIS | `Claude AI Installer-x.x.x-win-x64-nsis.exe` | 安装程序 | | Portable | `Claude AI Installer-x.x.x-win-x64-portable.exe` | 便携版 | ### macOS | 格式 | 文件名 | 说明 | |------|--------|------| | DMG | `Claude AI Installer-x.x.x-mac-x64-dmg.dmg` | Intel 版 | | DMG | `Claude AI Installer-x.x.x-mac-arm64-dmg.dmg` | Apple Silicon 版 | | ZIP | `Claude AI Installer-x.x.x-mac-x64-zip.zip` | Intel 压缩包 | | ZIP | `Claude AI Installer-x.x.x-mac-arm64-zip.zip` | Apple Silicon 压缩包 | ### Linux | 格式 | 文件名 | 说明 | |------|--------|------| | AppImage | `Claude AI Installer-x.x.x-linux-x64-AppImage.AppImage` | 通用格式 | | DEB | `Claude AI Installer-x.x.x-linux-x64-deb.deb` | Debian/Ubuntu | | RPM | `Claude AI Installer-x.x.x-linux-x64-rpm.rpm` | Fedora/RHEL | --- ## 跨平台构建注意事项 ### 在 Windows 上构建 - **Windows**: 原生支持 - **macOS**: 不支持(需要 macOS 系统) - **Linux**: 需要 WSL 或 Docker ### 在 macOS 上构建 - **Windows**: 需要安装 Wine (`brew install --cask wine-stable`) - **macOS**: 原生支持 - **Linux**: 原生支持 ### 在 Linux 上构建 - **Windows**: 需要安装 Wine - **macOS**: 不支持(需要 macOS 系统) - **Linux**: 原生支持 ### 使用 CI/CD 构建所有平台 推荐使用 GitHub Actions 等 CI/CD 服务在各自平台的 runner 上构建: ```yaml # .github/workflows/build.yml 示例 jobs: build: strategy: matrix: os: [windows-latest, macos-latest, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 - run: npm install - run: npm run build ``` --- ## 发布流程 ### 标准发布流程 1. 确保所有更改已提交 2. 运行发布命令: ```bash npm run release:patch # 或 minor/major ``` 3. 检查 `release/` 目录中的构建产物 4. 手动推送(如果没有使用 `--push`): ```bash git push && git push --tags ``` 5. 在 GitHub 创建 Release,上传构建产物 ### 自动发布流程 ```bash # 一键完成:更新版本 → 构建 → 创建 tag → 推送 node scripts/release.js patch --tag --push ``` --- ## 故障排除 ### 构建失败 1. 确保已安装所有依赖:`npm install` 2. 清理旧的构建文件:删除 `dist/` 和 `dist-electron/` 目录 3. 检查 Node.js 版本(推荐 18+) ### 图标问题 确保以下图标文件存在: - Windows: `public/icons/win/icon.ico` - macOS: `public/icons/mac/icon.icns` - Linux: `public/icons/png/` (包含各尺寸 PNG) ### 签名问题 - **Windows**: 需要代码签名证书(可选) - **macOS**: 需要 Apple Developer 证书进行公证(发布到 App Store 必需)