phase

一个 Swift 包,允许你从 Package.swift 清单文件定义你的 Xcode 构建阶段。

用法

像这样,在你的 Package.swift 文件的最底部定义你的构建阶段。

#if canImport(PhaseConfig)
import PhaseConfig

PhaseConfig(phases: [
    Phase(
        name: "Swift Lint", 
        script: "swiftlint", // actual bash script that will be added to xcodeproj build phase
        targets: ["SomeTarget", "AnotherTarget"] // targets on which to apply
    ),
    Phase(
        name: "Generate code",
        script: "sourcery",
        targets: ["OneMoreTarget"]
    ),
    Phase(
        name: "xcode", // a phase to easily generate and inject phases in freshly made xcode project
        script: "swift run package-config;swift package generate-xcodeproj;swift run phase install --verbose",
        targets: [] // wont be installed on any targets, can be triggered via bash as "swift run phase run xcode"
    ),
]).write()
#endif

每当你需要将你的构建阶段注入到 xcodeproj 文件中时,从包含 Package.swift 的目录运行此命令。

swift run phase install

每当你希望从命令行在包含 Package.swift 的项目目录中执行你的 phase 时。

swift run phase run yourPhaseName

还要考虑到你可能不需要将 Xcode 包含在你的代码仓库中,所以你可以将这行代码 /*.xcodeproj 添加到你的 .gitignore 文件中。并且,每当你需要你的 Xcode 项目时,只需运行 swift package generate-xcodeproj,然后你就可以使用 phase 将构建阶段注入到你的 Xcode 项目中。

安装

在你的项目 Package.swift 文件的 dependencies 中添加依赖

dependencies: [
    .package(url: "https://github.com/IgorMuzyka/phase", from: "0.0.5"),  
],

在你的 targets 中添加 PackageConfigs target,并在那里列出 PhaseConfig

.target(name: "PackageConfigs", dependencies: [
    "PhaseConfig",
]),

为了确保你可以运行 phase,请在你的项目目录中(包含 Package.swift)运行此命令。

swift run package-config # builds PackageConfigs dependencies