guide-macos-spm-packaging

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Guide Skill — This is an expert workflow/pattern guide, not API reference documentation. Originally from Dimillian/Skills by Thomas Ricouard. MIT License.
指南技能 — 这是一份专家级工作流/模式指南,而非API参考文档。 最初来自Thomas Ricouard的Dimillian/Skills项目,采用MIT License。

macOS SwiftPM App Packaging (No Xcode)

无需Xcode的macOS SwiftPM应用打包

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.
引导搭建一套完整的SwiftPM macOS应用目录,随后无需Xcode即可完成构建、打包和运行。你可以使用
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 tag,将zip包/appcast文件上传到GitHub Release页面并发布。

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
    :对发布版本进行公证、打钉、打包成zip。
  • assets/templates/make_appcast.sh
    :生成用于更新的Sparkle appcast条目。
  • 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
    配置。