I have an SPM package hosted at https://github.com/janodev/foobar
.
How can I generate documentation with Docc and host it at GitHub?
let package = Package(
platforms: [
.iOS(.v15), .macOS(.v12)
],
dependencies: [
.package(url: "[email protected]:apple/swift-docc-plugin.git", branch: "main"),
],
targets: [
// ...
]
)
# note this is for GitHub hosting, with a specific target and base path 'Foobar'
# don’t forget to build or you’ll get blank pages
swift build
# parameter values are case-sensitive!
swift package \
--allow-writing-to-directory ./docs \
generate-documentation \
--target Foobar \
--output-path ./docs \
--transform-for-static-hosting \
--hosting-base-path foobar
Or, if the package contains iOS frameworks, run this instead:
xcodebuild build -scheme Foobar -destination generic/platform=iOS
xcodebuild docbuild -scheme Foobar \
-destination generic/platform=iOS \
OTHER_DOCC_FLAGS="--transform-for-static-hosting --output-path docs --hosting-base-path foobar"
This means pushing the docs
directory to the GitHub repo. It may take a minute, or several, and your browser cache may deceive you, but it should appear at:
# username repository target
https://janodev.github.io/foobar/documentation/foobar
Note that my repository name was lowercase so I used -hosting-base-path foobar
. The target path component, however, is always lowercase, Idk why.
For any troubleshooting check the bug database:
This Makefile may be of help generating documentation for a SPM package.