See also https://www.whynotestflight.com/excuses/what-if-instead-of-a-cli-plugins-part-1-command-plugins/
Repo for exploring how to make Package Plugins.
- TellMeAboutYourself: Command Plugin. Write a report about the target to a file at the top level of the target. Discussed in WhyNoTestFlight plugin series part 1
- MyInBuildPlugin: Makes code based on text files. See also BuildPluginExample and BuildPluginExample, Discussed on WhyNotTestFlight Start Up, Code Gen
- MyPreBuildPlugin: Experiments in making zip files and where they can be put. Discussed on plugin series part 4
- ScreamIntoTheVoid: Trying to figure out where all the pipes are (STOUT, STDERR for plugin, for tool, etc.). WIP.
- BuildNRun: Also part 4. A command plugin that manages a build via the packageManager proxy.
swift package plugin --list
swift package $PLUGIN_VERB
swift package --allow-writing-to-package-directory $PLUGIN_VERB
swift package --disable-sandbox $PLUGIN_VERB
swift package init --type tool #Comes with argument parser
swift package init --type build-tool-plugin
swift package init --type command-plugin
- run on demand, makes edits to source/package folder: command plugin
- run only if resources are missing or stale: build plugin
- run every build, before the build: pre-build plugin
- Code generated by build plugins is generally detectable by IDE's, but the build tool has to have been run at least once before you can use it.
- Code only associated with a
.plugin
target doesn't get swept up in targets, and build problems can only be found in the build logs. Code also in its own stand alone tool does get more regular treatment. Prioritize putting as much as possible into a tool and as little a possible only in a plugin. - Write the tool and get it completely working, then write the plugin.
- stdout for a tool does not always work as expected.
- For two plugins to share code they need to both depend on the same executable or a binary, not a non-productized library target. See discussion
- Adding new files to the source directory is expensive to build plugins. It will rerun not just the plugin, but regenerate every command and run the tool(s).
- WWDC 2022 Meet Swift Package plugins
- WWDC 2022 Create Swift Package plugins
- https://github.com/apple/swift-package-manager/
- https://forums.swift.org/t/pitch-package-manager-command-plugins/53172
- https://github.com/apple/swift-evolution/blob/main/proposals/0332-swiftpm-command-plugins.md
- https://github.com/apple/swift-package-manager/blob/main/Documentation/Plugins.md
- Example bringing in linting from
MessageKit
https://github.com/MessageKit/MessageKit/tree/3fab2f2d7f04b0f7ec19e2bfab0f614fef884ff8/Plugins - https://github.com/SwiftGen/SwiftGenPlugin
- https://github.com/realm/SwiftLint/tree/main/Plugins/SwiftLintPlugin
- https://github.com/apple/swift-docc-plugin
- https://github.com/apple/swift-openapi-generator/tree/main/Plugins
- https://github.com/lighter-swift