macos-spm-app-packaging

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

macOS SwiftPM App Packaging (No Xcode)

macOS SwiftPM App Packaging (No Xcode)

Overview

概述

Bootstrap a complete SwiftPM macOS app folder, then build, package, and run it without Xcode. Use
assets/templates/bootstrap/
for the starter layout and
references/packaging.md
+
references/release.md
for packaging and release details.
无需Xcode,即可快速搭建完整的SwiftPM macOS应用文件夹,然后进行构建、打包和运行。使用
assets/templates/bootstrap/
获取初始布局,参考
references/packaging.md
references/release.md
了解打包和发布细节。

Two-Step Workflow

两步工作流程

  1. Bootstrap the project folder
    • Copy
      assets/templates/bootstrap/
      into a new repo.
    • Rename
      MyApp
      in
      Package.swift
      ,
      Sources/MyApp/
      , and
      version.env
      .
    • Customize
      APP_NAME
      ,
      BUNDLE_ID
      , and versions.
  2. Build, package, and run the bootstrapped app
    • Copy scripts from
      assets/templates/
      into your repo (for example,
      Scripts/
      ).
    • Build/tests:
      swift build
      and
      swift test
      .
    • Package:
      Scripts/package_app.sh
      .
    • Run:
      Scripts/compile_and_run.sh
      (preferred) or
      Scripts/launch.sh
      .
    • Release (optional):
      Scripts/sign-and-notarize.sh
      and
      Scripts/make_appcast.sh
      .
    • Tag + GitHub release (optional): create a git tag, upload the zip/appcast to the GitHub release, and publish.
  1. 搭建项目文件夹
    • assets/templates/bootstrap/
      复制到新仓库中。
    • Package.swift
      Sources/MyApp/
      version.env
      中重命名
      MyApp
    • 自定义
      APP_NAME
      BUNDLE_ID
      和版本信息。
  2. 构建、打包并运行已搭建的应用
    • assets/templates/
      中的脚本复制到你的仓库中(例如
      Scripts/
      目录)。
    • 构建/测试:执行
      swift build
      swift test
    • 打包:执行
      Scripts/package_app.sh
    • 运行:执行
      Scripts/compile_and_run.sh
      (推荐)或
      Scripts/launch.sh
    • 发布(可选):执行
      Scripts/sign-and-notarize.sh
      Scripts/make_appcast.sh
    • 打标签+GitHub发布(可选):创建git标签,将zip包/应用更新提要上传到GitHub发布页,然后发布。

Templates

模板

  • assets/templates/package_app.sh
    : Build binaries, create the .app bundle, copy resources, sign.
  • assets/templates/compile_and_run.sh
    : Dev loop to kill running app, package, launch.
  • assets/templates/build_icon.sh
    : Generate .icns from an Icon Composer file (requires Xcode install).
  • assets/templates/sign-and-notarize.sh
    : Notarize, staple, and zip a release build.
  • assets/templates/make_appcast.sh
    : Generate Sparkle appcast entries for updates.
  • assets/templates/setup_dev_signing.sh
    : Create a stable dev code-signing identity.
  • assets/templates/launch.sh
    : Simple launcher for a packaged .app.
  • assets/templates/version.env
    : Example version file consumed by packaging scripts.
  • assets/templates/bootstrap/
    : Minimal SwiftPM macOS app skeleton (Package.swift, Sources/, version.env).
  • assets/templates/package_app.sh
    :构建二进制文件、创建.app包、复制资源、签名。
  • assets/templates/compile_and_run.sh
    :开发循环脚本,用于终止运行中的应用、打包、启动应用。
  • assets/templates/build_icon.sh
    :从Icon Composer文件生成.icns图标(需要安装Xcode)。
  • assets/templates/sign-and-notarize.sh
    :对发布版本进行公证、装订并压缩。
  • assets/templates/make_appcast.sh
    :为更新生成Sparkle应用更新提要条目。
  • assets/templates/setup_dev_signing.sh
    :创建稳定的开发代码签名身份。
  • assets/templates/launch.sh
    :用于启动已打包.app的简单启动器。
  • assets/templates/version.env
    :供打包脚本读取的示例版本文件。
  • assets/templates/bootstrap/
    :极简SwiftPM macOS应用骨架(包含Package.swift、Sources/、version.env)。

Notes

注意事项

  • Keep entitlements and signing configuration explicit; edit the template scripts instead of reimplementing.
  • Remove Sparkle steps if you do not use Sparkle for updates.
  • Sparkle relies on the bundle build number (
    CFBundleVersion
    ), so
    BUILD_NUMBER
    in
    version.env
    must increase for each update.
  • For menu bar apps, set
    MENU_BAR_APP=1
    when packaging to emit
    LSUIElement
    in Info.plist.
  • 明确保留权限和签名配置;编辑模板脚本而非重新实现。
  • 如果你不使用Sparkle进行更新,请移除相关步骤。
  • Sparkle依赖于包构建编号(
    CFBundleVersion
    ),因此
    version.env
    中的
    BUILD_NUMBER
    必须在每次更新时递增。
  • 对于菜单栏应用,打包时设置
    MENU_BAR_APP=1
    ,以在Info.plist中添加
    LSUIElement