feat: 支持 macOS arm64 打包,修复图标未入库

新增 build-mac.js,产出 ad-hoc 签名的 .app 与 DMG。只能在 macOS 上
构建:DMG 依赖 hdiutil,且 Apple Silicon 拒绝执行未签名二进制,改名
与改 plist 后必须用 codesign 重签。

按官方 darwin-arm64 运行时的真实结构处理四处易错点:用 ditto 解压以
保留 framework 符号链接、删除重打包后失效的 ElectronAsarIntegrity、
为改名后的 helper 补上 CFBundleExecutable、签名由内向外且单独签
Squirrel 的 ShipIt。

打包版数据目录改为按平台决定:macOS 走 appData,避免写进 DMG 挂载后
只读的 .app 内部并在升级覆盖时丢失书库;Windows 便携版行为不变。
窗口图标在非 Windows 平台改用 PNG。

.gitignore 的 dist 规则补上前导斜杠。此前它同时匹配 icons/dist/,
导致构建与单测依赖的图标从未入库,新克隆的仓库无法构建。
This commit is contained in:
lofyer
2026-08-03 16:18:47 +08:00
parent 2c5c7b1828
commit 381c07733a
28 changed files with 597 additions and 10 deletions
+30 -2
View File
@@ -21,6 +21,30 @@ npm run portable
发布时将完整的 `dist/PeopleLib-windows-x64/` 目录压缩,上传到 GitHub Release,并使用 `v1.3.0` 形式的版本标签。应用根据最新 Release 标签判断是否需要更新。
### macOSApple Silicon
**只能在 macOS 上执行**,且需要 Xcode 命令行工具(`xcode-select --install`):
```bash
npm install
npm run build:mac
```
产出 `dist/PeopleLib-macos-arm64/PeopleLib.app``dist/PeopleLib-macos-arm64.dmg`
不能在 Windows 或 Linux 上交叉构建,原因有两条,都无法绕开:
- DMG 由 `hdiutil` 生成,该工具只存在于 macOS。
- Apple Silicon 内核会拒绝执行未签名的二进制。打包过程要重命名可执行文件、修改 `Info.plist`,Electron 的原始签名必然失效,必须用 macOS 的 `codesign` 重新签名。
脚本使用 ad-hoc 签名(`codesign --sign -`),可以在本机及自行放行的机器上运行,但未经 Apple 公证。首次打开需右键点按图标选择「打开」,或执行:
```bash
xattr -dr com.apple.quarantine /Applications/PeopleLib.app
```
图标 `icons/dist/book-ai-*.icns` 已随仓库提供。源 PNG 变更后用 `npm run icons:icns` 重新生成,该脚本在任意平台都能运行,不依赖 macOS 的 `iconutil`
## 配置
### 代理
@@ -39,8 +63,12 @@ npm run portable
| 模式 | 路径 |
|---|---|
| 开发运行 | `%APPDATA%/PeopleLib`Windows |
| 打包运行 | 可执行文件同级的 `data/` 目录 |
| 开发运行Windows | `%APPDATA%/PeopleLib` |
| 开发运行(macOS | `~/Library/Application Support/PeopleLib` |
| 打包运行(Windows 便携版) | 可执行文件同级的 `data/` 目录 |
| 打包运行(macOS | `~/Library/Application Support/PeopleLib` |
macOS 不采用便携布局:`.app` 内部在 DMG 挂载时只读,且覆盖升级会连同用户书库一并删除。
该目录包含: