package.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # Build ../dist/DoTouchAI.app + a drag-install DMG from the local electron
  3. # dist + app sources. (Manual bundle construction: deterministic, no network,
  4. # no @electron/get.)
  5. set -euo pipefail
  6. cd "$(dirname "$0")/.."
  7. SRC="node_modules/electron/dist/Electron.app"
  8. OUT="../dist"
  9. APP="$OUT/DoTouchAI.app"
  10. PLIST="$APP/Contents/Info.plist"
  11. VERSION="$(node -p "require('./package.json').version")"
  12. DMG="$OUT/DoTouchAI-${VERSION}-arm64.dmg"
  13. rm -rf "$APP"
  14. mkdir -p "$OUT" "$APP/Contents/Resources/app/assets"
  15. cp -R "$SRC/." "$APP/"
  16. rm -rf "$APP/Contents/Resources/default_app.asar"
  17. # App sources — this shell has zero runtime npm deps, so node_modules stays out.
  18. cp main.js env.js service.js updater.js plugins.js package.json "$APP/Contents/Resources/app/"
  19. cp assets/trayTemplate.png assets/trayTemplate@2x.png assets/icon.icns \
  20. "$APP/Contents/Resources/app/assets/"
  21. # Build metadata (shown in the About dialog so installs are distinguishable).
  22. node -e "require('fs').writeFileSync('$APP/Contents/Resources/app/build.json', JSON.stringify({version:'$VERSION', builtAt:new Date().toLocaleString('zh-CN',{hour12:false})}, null, 2) + '\n')"
  23. # Bundled dsh plugins (voice suite) — copied from DSWorkSpace, deps hoisted
  24. # flat next to the plugins (same layout the profile already uses), and
  25. # auto-installed into the web profile on first launch (see app/plugins.js).
  26. # Dep sources come from the live profile root (the real files — the
  27. # DSWorkSpace copies are pnpm symlinks).
  28. VOICE_SRC="/Users/eastudio/Documents/DSWorkSpace"
  29. DEP_SRC="$HOME/.dsh/profiles/web/node_modules"
  30. BUNDLED="$APP/Contents/Resources/app/plugins"
  31. mkdir -p "$BUNDLED"
  32. rm -rf "$BUNDLED"/*
  33. cp -R "$VOICE_SRC/dsh-voice-client" "$BUNDLED/dsh-voice-client"
  34. rm -rf "$BUNDLED/dsh-voice-client/node_modules"
  35. cp -R "$VOICE_SRC/dsh-voice-server" "$BUNDLED/dsh-voice-server"
  36. rm -rf "$BUNDLED/dsh-voice-server/node_modules"
  37. for dep in sherpa-onnx-node sherpa-onnx-darwin-arm64 ws; do
  38. cp -R "$DEP_SRC/$dep" "$BUNDLED/$dep"
  39. done
  40. node -e "require('fs').writeFileSync('$BUNDLED/manifest.json', JSON.stringify({
  41. 'dsh-voice-client': { id: 'dsh-voice-client', name: 'dsh-voice-client' },
  42. 'dsh-voice-server': { id: 'dsh-voice-server', name: 'dsh-voice-server/lib/index-v6.js' },
  43. 'sherpa-onnx-node': { dep: true },
  44. 'sherpa-onnx-darwin-arm64': { dep: true },
  45. 'ws': { dep: true }
  46. }, null, 2) + '\n')"
  47. echo "bundled plugins: $(du -sh "$BUNDLED" | cut -f1) — $(ls "$BUNDLED" | tr '\n' ' ')"
  48. # Identity + icon.
  49. cp assets/icon.icns "$APP/Contents/Resources/electron.icns"
  50. plutil -replace CFBundleName -string "DoTouchAI" "$PLIST"
  51. plutil -replace CFBundleDisplayName -string "DoTouchAI" "$PLIST"
  52. plutil -replace CFBundleIdentifier -string "local.eastudio.dsh-desktop" "$PLIST"
  53. plutil -replace CFBundleShortVersionString -string "$VERSION" "$PLIST"
  54. # Ad-hoc signature: no Apple ID needed, silences Gatekeeper's unsigned-binary nag.
  55. codesign --force --sign - "$APP" >/dev/null 2>&1 || true
  56. echo "built: $APP ($(du -sh "$APP" | cut -f1))"
  57. # Drag-install DMG: the app beside a symlink to /Applications.
  58. STAGING="../.dmg-staging"
  59. rm -rf "$STAGING"
  60. mkdir -p "$STAGING"
  61. cp -R "$APP" "$STAGING/"
  62. ln -sfn /Applications "$STAGING/Applications"
  63. rm -f "$DMG"
  64. hdiutil create -volname "DoTouchAI $VERSION" -srcfolder "$STAGING" -ov -format UDZO "$DMG" >/dev/null
  65. rm -rf "$STAGING"
  66. hdiutil verify "$DMG" >/dev/null && echo "built: $DMG ($(du -sh "$DMG" | cut -f1))"