🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"
TypeScript
chore: release desktop 4.0.9 with macOS packaging fixes
Connor3c6fdd68a6c2
diff --git a/desktop/electron-builder.yml b/desktop/electron-builder.ymlindex 0623e15..01cfbfd 100644--- a/desktop/electron-builder.yml+++ b/desktop/electron-builder.yml@@ -18,9 +18,8 @@ asarUnpack:extraResources:- { from: resources/frontend, to: frontend }- { from: resources/workspace-template, to: workspace-template }- # ${os} 宏:mac → bin-mac/(无扩展名二进制),win → bin-win/(.exe),- # 各自只带本平台的 ffmpeg/ffprobe- - { from: "resources/bin-${os}", to: bin }+ # 按系统与 CPU 架构选择 ffmpeg/ffprobe,避免 Intel Mac 包带入 ARM 二进制。+ - { from: "resources/bin-${os}-${arch}", to: bin }npmRebuild: true# win 交叉打包修复:宿主机(mac)下载的原生预编译是 Mach-O,afterPack 换入官方 win32 .nodeafterPack: scripts/after-pack.mjsdiff --git a/desktop/package-lock.json b/desktop/package-lock.jsonindex 1d3cd37..66011c3 100644--- a/desktop/package-lock.json+++ b/desktop/package-lock.json@@ -1,14 +1,14 @@{"name": "huobao-drama-desktop",- "version": "4.0.8",+ "version": "4.0.9","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "huobao-drama-desktop",- "version": "4.0.8",+ "version": "4.0.9",+ "hasInstallScript": true,"dependencies": {- "@img/sharp-win32-x64": "0.34.5","better-sqlite3": "^12.4.1","sharp": "^0.34.5"},@@ -21,6 +21,8 @@"ffprobe-static": "^3.1.0"},"optionalDependencies": {+ "@img/sharp-darwin-x64": "^0.34.5",+ "@img/sharp-libvips-darwin-x64": "^1.2.4","@img/sharp-win32-x64": "^0.34.5"}},@@ -863,7 +865,7 @@},"node_modules/@img/sharp-darwin-x64": {"version": "0.34.5",- "resolved": "https://packages.aliyun.com/69c39010f167bac7fd2502e3/npm/npm-registry/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.5.tgz",+ "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.5.tgz","integrity": "sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==","cpu": ["x64"@@ -901,7 +903,7 @@},"node_modules/@img/sharp-libvips-darwin-x64": {"version": "1.2.4",- "resolved": "https://packages.aliyun.com/69c39010f167bac7fd2502e3/npm/npm-registry/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.4.tgz",+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.4.tgz","integrity": "sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==","cpu": ["x64"diff --git a/desktop/package.json b/desktop/package.jsonindex d699c60..bce3edc 100644--- a/desktop/package.json+++ b/desktop/package.json@@ -1,7 +1,7 @@{"name": "huobao-drama-desktop","productName": "HuobaoDrama",- "version": "4.0.8",+ "version": "4.0.9","private": true,"description": "火宝短剧桌面版(Electron 壳)","author": "Huobao",@@ -30,6 +30,8 @@"ffprobe-static": "^3.1.0"},"optionalDependencies": {+ "@img/sharp-darwin-x64": "^0.34.5",+ "@img/sharp-libvips-darwin-x64": "^1.2.4","@img/sharp-win32-x64": "^0.34.5"}}diff --git a/desktop/scripts/after-pack.mjs b/desktop/scripts/after-pack.mjsindex b08fc64..3d32e4d 100644--- a/desktop/scripts/after-pack.mjs+++ b/desktop/scripts/after-pack.mjs@@ -14,6 +14,8 @@ import fs from 'node:fs'import path from 'node:path'import { fileURLToPath } from 'node:url'import { validateWindowsPackage, assertWindowsX64 } from './validate-windows-package.mjs'+import { Arch } from 'builder-util'+import { assertMacArchitecture } from './prepare-mac-media.mjs'const WIN_BIN = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'build', 'win-bin', 'better_sqlite3.node')@@ -26,9 +28,24 @@ export default async function afterPack(context) {const exe = context.electronPlatformName === 'win32' ? '.exe' : ''for (const name of [`ffmpeg${exe}`, `ffprobe${exe}`]) {const p = path.join(resourcesDir, 'bin', name)- if (!fs.existsSync(p)) throw new Error(`打包产物缺少 bin/${name}(检查 prepare-resources 与 \${os} 目录命名)`)+ if (!fs.existsSync(p)) throw new Error(`打包产物缺少 bin/${name}(检查 prepare-resources 的平台与架构目录)`)+ if (context.electronPlatformName === 'darwin') assertMacArchitecture(p, Arch[context.arch])}+ if (context.electronPlatformName === 'darwin') {+ const arch = Arch[context.arch]+ const nativeRoot = path.join(resourcesDir, 'app.asar.unpacked', 'node_modules')+ for (const file of [+ path.join(nativeRoot, 'better-sqlite3', 'build', 'Release', 'better_sqlite3.node'),+ path.join(nativeRoot, '@img', `sharp-darwin-${arch}`, 'lib', `sharp-darwin-${arch}.node`),+ ]) assertMacArchitecture(file, arch)+ const vips = path.join(nativeRoot, '@img', `sharp-libvips-darwin-${arch}`, 'lib')+ const libraries = fs.readdirSync(vips).filter(file => file.endsWith('.dylib'))+ if (!libraries.length) throw new Error(`缺少 macOS ${arch} libvips 动态库`)+ for (const file of libraries) assertMacArchitecture(path.join(vips, file), arch)+ console.log(`[package-check] macOS ${arch} 媒体工具与原生模块架构一致 ✓`)+ return+ }if (context.electronPlatformName !== 'win32') returnif (!fs.existsSync(WIN_BIN)) {throw new Error(diff --git a/desktop/scripts/prepare-mac-media.mjs b/desktop/scripts/prepare-mac-media.mjsnew file mode 100644index 0000000..7f9b935--- /dev/null+++ b/desktop/scripts/prepare-mac-media.mjs@@ -0,0 +1,63 @@+import fs from 'node:fs'+import path from 'node:path'+import { execFile, execFileSync } from 'node:child_process'+import { createRequire } from 'node:module'+import { promisify } from 'node:util'+import { createGunzip } from 'node:zlib'+import { pipeline } from 'node:stream/promises'++const run = promisify(execFile)+const require = createRequire(import.meta.url)+const release = require('ffmpeg-static/package.json')['ffmpeg-static']['binary-release-tag']++export function assertMacArchitecture(file, arch) {+ execFileSync('lipo', ['-verify_arch', arch === 'x64' ? 'x86_64' : arch, file], { stdio: 'pipe' })+}++export async function prepareMacMedia(desktop, resources) {+ // npm skips optional binaries for the other CPU even when they are declared.+ // Fetch exact versions from sharp's dependency map before cross-packaging.+ const optional = require('sharp/package.json').optionalDependencies+ for (const arch of ['arm64', 'x64']) {+ for (const name of [`sharp-darwin-${arch}`, `sharp-libvips-darwin-${arch}`]) {+ const destination = path.join(desktop, 'node_modules', '@img', name)+ if (fs.existsSync(path.join(destination, 'package.json'))) continue+ const cache = path.join(desktop, 'build', 'mac-native', name)+ fs.mkdirSync(cache, { recursive: true })+ const { stdout } = await run('npm', ['pack', `@img/${name}@${optional[`@img/${name}`]}`,+ '--ignore-scripts', '--json', '--registry=https://registry.npmjs.org', '--pack-destination', cache])+ const [{ filename }] = JSON.parse(stdout)+ fs.mkdirSync(destination, { recursive: true })+ await run('tar', ['-xzf', path.join(cache, filename), '--strip-components=1', '-C', destination])+ console.log(`[native] ${name} ✓`)+ }+ }+ await Promise.all(['arm64', 'x64'].flatMap(arch => ['ffmpeg', 'ffprobe'].map(async name => {+ const cache = path.join(desktop, 'build', 'mac-bin', release, arch)+ const binary = path.join(cache, name)+ fs.mkdirSync(cache, { recursive: true })+ if (!fs.existsSync(binary)) {+ const archive = `${binary}.gz.part`+ const temporary = `${binary}.part`+ try {+ console.log(`[media] downloading ${name} for macOS ${arch} (${release})`)+ await run('curl', ['--fail', '--location', '--silent', '--show-error', '--retry', '3',+ '--connect-timeout', '15', '--max-time', '300', '--output', archive,+ `https://github.com/eugeneware/ffmpeg-static/releases/download/${release}/${name}-darwin-${arch}.gz`])+ await pipeline(fs.createReadStream(archive), createGunzip(), fs.createWriteStream(temporary))+ assertMacArchitecture(temporary, arch)+ fs.chmodSync(temporary, 0o755)+ fs.renameSync(temporary, binary)+ } finally {+ fs.rmSync(archive, { force: true })+ fs.rmSync(temporary, { force: true })+ }+ }+ assertMacArchitecture(binary, arch)+ const dest = path.join(resources, `bin-mac-${arch}`)+ fs.mkdirSync(dest, { recursive: true })+ fs.copyFileSync(binary, path.join(dest, name))+ fs.chmodSync(path.join(dest, name), 0o755)+ console.log(`[media] ${arch}/${name} ✓`)+ })))+}diff --git a/desktop/scripts/prepare-resources.mjs b/desktop/scripts/prepare-resources.mjsindex bbf3bc2..0ebb0ef 100644--- a/desktop/scripts/prepare-resources.mjs+++ b/desktop/scripts/prepare-resources.mjs@@ -3,13 +3,14 @@** 1. frontend/ ← nuxt generate 产物(.output/public,含 index.html)* 2. workspace-template/ ← backend/workspace(skills + prompts,首启动拷入 userData)- * 3. bin-<os>/ ← ffmpeg/ffprobe 按平台分目录(electron-builder ${os} 宏各取所需,+ * 3. bin-<os>-<arch>/ ← ffmpeg/ffprobe 按平台与架构分目录(electron-builder 宏各取所需,* 避免 mac 包带 exe、win 包带 mac 二进制白白 +144MB)*/import fs from 'fs'import path from 'path'import { fileURLToPath } from 'url'import { createRequire } from 'module'+import { prepareMacMedia } from './prepare-mac-media.mjs'const __dirname = path.dirname(fileURLToPath(import.meta.url))const DESKTOP = path.resolve(__dirname, '..')@@ -33,25 +34,12 @@ const workspaceSrc = path.join(REPO, 'backend', 'workspace')fs.cpSync(workspaceSrc, path.join(RES, 'workspace-template'), { recursive: true })console.log('resources/workspace-template ✓')-// 3. ffmpeg 二进制(macOS/Linux 用 ffmpeg-static 当前平台的产物;-// Windows 交叉打包:ffmpeg.exe 从 ffmpeg-static GitHub release 获取(本地缓存),-// ffprobe.exe 直接用 ffprobe-static 自带的 win32/x64 产物)+// 3. macOS 两种架构独立准备;ffprobe-static 的 arm64 目录实际可能含 x64 二进制,+// 因此两种媒体工具统一使用 ffmpeg-static 对应版本的官方发布产物。const req = createRequire(import.meta.url)-const binMac = path.join(RES, 'bin-mac')-const binWin = path.join(RES, 'bin-win')-fs.mkdirSync(binMac, { recursive: true })+if (process.platform === 'darwin') await prepareMacMedia(DESKTOP, RES)+const binWin = path.join(RES, 'bin-win-x64')fs.mkdirSync(binWin, { recursive: true })-const ffmpegPath = req('ffmpeg-static')-const ffprobePath = req('ffprobe-static')?.path-if (!ffmpegPath || !ffprobePath || !fs.existsSync(ffmpegPath) || !fs.existsSync(ffprobePath)) {- console.error('ffmpeg-static/ffprobe-static 二进制缺失,请重新 npm install(或配置 FFMPEG_BINARIES_URL 镜像)')- process.exit(1)-}-fs.copyFileSync(ffmpegPath, path.join(binMac, 'ffmpeg'))-fs.copyFileSync(ffprobePath, path.join(binMac, 'ffprobe'))-fs.chmodSync(path.join(binMac, 'ffmpeg'), 0o755)-fs.chmodSync(path.join(binMac, 'ffprobe'), 0o755)-console.log('resources/bin-mac ✓')// 3b. Windows 二进制(打 win 包用;不打 win 包时缺失不报错,仅提示)const winBinDir = path.join(DESKTOP, 'build', 'win-bin')@@ -64,5 +52,5 @@ if (!fs.existsSync(ffmpegWin)) {if (fs.existsSync(ffmpegWin) && fs.existsSync(ffprobeWinSrc)) {fs.copyFileSync(ffmpegWin, path.join(binWin, 'ffmpeg.exe'))fs.copyFileSync(ffprobeWinSrc, path.join(binWin, 'ffprobe.exe'))- console.log('resources/bin-win ✓')+ console.log('resources/bin-win-x64 ✓')}