Swift Package Manager command plugin for Swift-DocC

Overview

Swift-DocC Plugin

The Swift-DocC plugin is a Swift Package Manager command plugin that supports building documentation for SwiftPM libraries and executables.

Usage

Please see the plugin's documentation for more detailed usage instructions.

Adding the Swift-DocC Plugin as a Dependency

To use the Swift-DocC plugin with your package, first add it as a dependency:

let package = Package(
    // name, platforms, products, etc.
    dependencies: [
        // other dependencies
        .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
    ],
    targets: [
        // targets
    ]
)

Swift 5.6 is required in order to run the plugin.

Converting Documentation

You can then invoke the plugin from the root of your repository like so:

swift package generate-documentation

This will generate documentation for all compatible targets defined in your package and its dependencies and print the location of the resulting DocC archives.

If you'd like to generate documentation for a specific target and output that to a specific directory, you can do something like the following:

swift package --allow-writing-to-directory ./docs \
    generate-documentation --target MyFramework --output-path ./docs

Notice that the output path must also be passed to SwiftPM via the --allow-writing-to-directory option. Otherwise SwiftPM will throw an error as it's a sandbox violation for a plugin to write to a package directory without explicit permission.

Any flag passed after the generate-documentation plugin invocation is passed along to the docc command-line tool. For example, to take advantage of Swift-DocC's new support for hosting in static environments like GitHub Pages, you could run the following:

swift package --allow-writing-to-directory ./docs \
    generate-documentation --target MyFramework --output-path ./docs \
    --transform-for-static-hosting --hosting-base-path MyFramework

Previewing Documentation

The Swift-DocC plugin also supports previewing documentation with a local web server. However, unlike converting documentation, previewing is limited to a single target a time.

To preview documentation for the MyFramework target, you could run the following:

swift package --disable-sandbox preview-documentation --target MyFramework

To preview documentation for a product defined by one of your package's dependencies, you could run the following:

swift package --disable-sandbox preview-documentation --product OtherFramework

Hosting Documentation

For details on how to best build documentation for hosting online and a specific tutorial for publishing to GitHub Pages, please see the plugin's documentation.

Submitting a Feature Request

For feature requests, please feel free to create an issue on Swift JIRA with the New Feature type or start a discussion on the Swift Forums.

Don't hesitate to submit a feature request if you see a way the Swift-DocC plugin can be improved to better meet your needs.

All user-facing features must be discussed in the Swift Forums before being enabled by default.

Contributing to the Swift-DocC Plugin

Please see the contributing guide for more information.

Comments
  • Adopt new SwiftPM plugin Argument Parsing API

    Adopt new SwiftPM plugin Argument Parsing API

    Summary

    Updates the SwiftPM plugin to use the latest Argument Parsing API that will ship with Swift 5.6.

    This also includes some general improvements to help output (--help) in preparation for the 1.0 release of the plugin.

    Details

    The SwiftPM plugin API has been updated so that options like --target and --product are passed directly to the plugin instead of to the package manager.

    This means that instead of calling the plugin with something like:

    swift package --target SwiftMarkdown generate-documentation
    

    you would now do:

    swift package generate-documentation --target SwiftMarkdown
    

    This allows us to be a little smarter about choosing which products to build. For example, now when a user invokes the basic

    swift package generate-documentation
    

    we will also generate documentation for dependencies. Similarly, this allows clients to specify products of dependencies which makes doing something like

    swift package preview-documetnation --product ArgumentParser
    

    possible for packages that import ArgumentParser.

    Dependencies

    This change depends on the latest Swift 5.6 nightly toolchain that includes the new ArgumentParsing API.

    Testing

    Add the version of the plugin on this branch as a dependency of a package with:

    .package(url: ["https://github.com/apple/swift-docc-plugin](https://github.com/ethan-kusters/swift-docc-plugin.git)", branch: "adopt-new-argument-parsing-api")
    

    Checklist

    Make sure you check off the following items. If they cannot be completed, provide a reason.

    • [x] Added tests
    • [x] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by ethan-kusters 16
  • SE-0356: Snippet slice parsing

    SE-0356: Snippet slice parsing

    Rewrite the snippet parser to support slicing.

    See: https://github.com/apple/swift-evolution/blob/main/proposals/0356-swift-snippets.md#slices

    Adopt SymbolKit model changes related to slicing.

    Remove experimental guard flag for snippet functionality.

    rdar://95220356

    opened by bitjammer 12
  • Update Documentation For Private Github Pages

    Update Documentation For Private Github Pages

    Bug/issue #, if applicable: https://forums.swift.org/t/docc-for-private-github-repos/55770/2

    Summary

    Added documentation for github private pages . For private repos, hosting-base-path is not needed, as each repo is served from its own subdomain. Also the url format for such pages is also different.

    Dependencies

    Not Applicable

    Testing

    Not Applicable

    Checklist

    • [ ] Added tests
    • [ ] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by denil-ct 9
  • Snippets

    Snippets

    Summary

    Add snippets support to the Swift DocC Plugin.

    Dependencies

    No outstanding PR dependencies, although this does add a new dependency on SymbolKit, which should match DocC's version.

    Testing

    New unit and integration tests added. Run tests as usual.

    Checklist

    Make sure you check off the following items. If they cannot be completed, provide a reason.

    • [x] Added tests
    • [x] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by bitjammer 7
  • [`./bin/test`] Allow skipping clone of `swift-docc` and `swift-docc-render-artifact`

    [`./bin/test`] Allow skipping clone of `swift-docc` and `swift-docc-render-artifact`

    From https://github.com/apple/swift-docc-plugin/pull/21#discussion_r929419898

    In some scenarios, running swift-docc-plugin tests against the built-in docc in the installed toolchain could save time. Add an option to ./bin/test to skip cloning swift-docc and swift-docc-render-artifact and setting the environment variables to use those.

    Behavior:

    If --skip-building-upstream-docc (or perhaps an environment variable) is set:

    • Don't set the following:
      • SWIFT_DOCC_ROOT
      • SWIFT_DOCC_RENDER_ARTIFACT_ROOT
      • SWIFT_DOCC_BRANCH
      • SWIFT_DOCC_RENDER_ARTIFACT_BRANCH
    • Don't clone swift-docc or swift-docc-render-artifact
    • Also don't set:
      • DOCC_EXEC
      • DOCC_HTML_DIR

    See the above mentioned pull request for new code that should be skipped in this case.

    enhancement good first issue improvement 
    opened by bitjammer 6
  • Make snippet-extract take individual input/output files instead of a directory

    Make snippet-extract take individual input/output files instead of a directory

    This does not change the experience for package authors but allows for better integration with other tools that require sandboxing of file access.

    rdar://103034070

    • [x] Added tests
    • [x] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by bitjammer 5
  • Snippet crash: No value associated with key 'chunks'

    Snippet crash: No value associated with key 'chunks'

    running a recent revision (00555b6efa14095243fbce031dba8a03cfc6333e) of this plugin on swift-json crashes with

    /home/klossy/dev/swift-json/Sources/JSON/JSON.docc/json.md:1:1: warning: Unknown directive 'import'; this element will be ignored
    /home/klossy/dev/swift-json/Sources/JSON/JSON.docc/json.md:2:1: warning: Unknown directive 'import'; this element will be ignored
    /home/klossy/dev/swift-json/Sources/JSON/JSON.docc/json.md:1:1: warning: An article is expected to start with a top-level heading title
    Error: keyNotFound(CodingKeys(stringValue: "chunks", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "symbols", intValue: nil), _JSONKey(stringValue: "Index 1", intValue: 1), CodingKeys(stringValue: "snippet", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: \"chunks\", intValue: nil) (\"chunks\").", underlyingError: nil))
    
    Generating documentation for 'LintingDictionary'...
    error: 'docc convert' invocation failed with a nonzero exit code: '1'
    error: unspecified("ExitCode(rawValue: 1)")
    

    Checklist

    • [x] If possible, I've reproduced the issue using the main branch of this package.
    • [x] This issue hasn't been addressed in an existing GitHub issue.

    Expected behavior

    swift-json’s documentation was written for Biome, so i don’t expect this plugin to handle all of its documentation by default, but it should probably ignore the invalid snippets gracefully instead of crashing.

    Actual behavior

    already described above.

    Steps to Reproduce

    1. clone swift-json at 59d34c5f8c337b068d07ad5b0e4caa2fd0b8176e, and replace its docgen tool with:
    .package(url: "https://github.com/apple/swift-docc-plugin", revision: "00555b6efa14095243fbce031dba8a03cfc6333e"),
    
    1. run $ swift package generate-documentation

    Swift-DocC Plugin Version Information

    Swift-DocC plugin version: 00555b6efa14095243fbce031dba8a03cfc6333e

    $ swift --version
    Swift version 5.8-dev (LLVM e41a0a126d143ae, Swift 23e5143d22cb768)
    Target: x86_64-unknown-linux-gnu
    $ swiftenv version
    DEVELOPMENT-SNAPSHOT-2022-07-25-a 
    
    bug 
    opened by kelvin13 5
  • Preview: remove use of `signal` on Windows

    Preview: remove use of `signal` on Windows

    Windows does not support signal(2). Instead, use TerminateProcess to terminate the process. We will not properly handle the termination of child processes for the preview process, which should be handled by the construction of a job object that all child processes are attached to such that when the parent process is terminated, the children will be properly reaped. This is required to enable building the plugin on Windows which is a dependency for swift-syntax.

    opened by compnerd 4
  • Disable integration tests on macOS to unblock CI

    Disable integration tests on macOS to unblock CI

    SwiftPM command plugins can only be run when the Swift concurrency libraries are available. For some reason these libraries are no longer available in the macOS used in SwiftCI so this disables those tests after performing a check to see if concurrency is available.

    This mirrors the implementation in SwiftPM itself here: https://github.com/apple/swift-package-manager/blob/dd7e9cc6/Sources/SPMTestSupport/Toolchain.swift#L55

    opened by ethan-kusters 3
  • Allow test script to use upstream DocC.

    Allow test script to use upstream DocC.

    Expect SWIFT_DOCC_BRANCH and SWIFT_DOCC_RENDER_ARTIFACT_BRANCH in the environment. If both are set when running ./bin/test, clone the respective repos at those branches and set DOCC_EXEC and DOCC_HTML_DIR when running the tests.

    Exclude these cloned directories from ./bin/check-source.

    rdar://97294776

    opened by bitjammer 3
  • Update for Github Issues Migration

    Update for Github Issues Migration

    Summary

    • Added issue templates for feature request and bug report. (based on swift-docc)
    • Updated feature requests and bug report sections of readme with the new templates.

    Checklist

    Make sure you check off the following items. If they cannot be completed, provide a reason.

    • [ ] Added tests
    • [ ] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by denil-ct 3
  • Cannot Specify Platform For Documents Generation

    Cannot Specify Platform For Documents Generation

    Currently we cannot specify the build platform for swift-docc-plugin. This means that the generate-documentation command only generates documentation for macOS. We hope that in the future there can be a -platform flag to allow document generation for a specific platform.

    Checklist

    • [X] If possible, I've reproduced the issue using the main branch of this package.
    • [X] This issue hasn't been addressed in an existing GitHub issue.

    Expected behavior

    There can be a -platform flag to allow document generation for a specific platform. For example, we can generate documents for iOS platform or tvOS platform.

    Actual behavior

    The generate-documentation command only generates documentation for macOS.

    Steps to Reproduce

    Run swift package generate-documentation, it is no possible to specify the platform information.

    Swift-DocC Plugin Version Information

    Swift-DocC plugin version: https://github.com/apple/swift-docc-plugin/commit/5f2e247f5efef4ff8ee603443a9a29225ce9f0e2 Swift Compiler version: swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.2 clang-1400.0.29.51) Target: arm64-apple-macosx13.0

    bug 
    opened by justinguo 0
  • Xcode 13 produces error `Cannot find type 'SnippetBuilder'` in scope

    Xcode 13 produces error `Cannot find type 'SnippetBuilder'` in scope

    Bug/issue #, if applicable: #36

    Summary

    Fix for bug introduced in https://github.com/apple/swift-docc-plugin/commit/5f2e247f5efef4ff8ee603443a9a29225ce9f0e2 refactor, where SnippetBuilder had to be refactored to SnippetExtractor.

    Dependencies

    N/A

    Testing

    N/A

    Checklist

    Make sure you check off the following items. If they cannot be completed, provide a reason.

    • [ ] Added tests
    • [x] Ran the ./bin/test script and it succeeded
    • [x] Updated documentation if necessary
    opened by sofiaromorales 0
  • Xcode 13 produces error `Cannot find type 'SnippetBuilder' in scope`

    Xcode 13 produces error `Cannot find type 'SnippetBuilder' in scope`

    When trying to generate documentation from the main branch with Swift 5.6 an error message appears Cannot find type 'SnippetBuilder' in scope, this does not happen in https://github.com/apple/swift-docc-plugin/commit/3e3305b6a71368ec9b86a5a5304fe64bab2c4605

    Checklist

    • [X] If possible, I've reproduced the issue using the main branch of this package.
    • [X] This issue hasn't been addressed in an existing GitHub issue.

    Expected behavior

    Documentation to be generated when using Swift 5.6

    Actual behavior

    Error Cannot find type 'SnippetBuilder' in scope is thrown

    Screen Shot 2022-12-02 at 10 34 59 PM

    Steps to Reproduce

    Using Swift 5.6 and running the command swift package generate-documentation against the main branch produces the error

    Swift-DocC Plugin Version Information

    Swift-DocC plugin version: https://github.com/apple/swift-docc-plugin/commit/5f2e247f5efef4ff8ee603443a9a29225ce9f0e2 (current HEAD -> main) Swift Compiler version: swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)

    bug 
    opened by sofiaromorales 0
  • `--enable-inherited-docs` flag is unused

    `--enable-inherited-docs` flag is unused

    The help for this package (which by the way, I haven't been able to get to using swift help package) shows --enable-inherited-docs. This seems to map to inheritDocs in Docc, but it appears that this flag isn't parsed at all.

    Checklist

    • [x] If possible, I've reproduced the issue using the main branch of this package.
    • [x] This issue hasn't been addressed in an existing GitHub issue.

    Expected behavior

    • --enable-inherited-docs is parsed and sent to Docc
    • --enable-inherited-docs is documented

    Actual behavior

    This flag is unused.

    Steps to Reproduce

    Example command:

    swift package --disable-sandbox --allow-writing-to-directory docs preview-documentation --target Target --disable-indexing --output-path docs --enable-inherited-docs --additional-symbol-graph-dir .build
    

    Swift-DocC Plugin Version Information

    Swift-DocC plugin version: https://github.com/apple/swift-docc-plugin/commit/5f2e247f5efef4ff8ee603443a9a29225ce9f0e2 Swift Compiler version:

    swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.2 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0
    
    bug 
    opened by NachoSoto 3
  • Add --include-extended-types flag

    Add --include-extended-types flag

    Bug/issue #, if applicable: apple/swift-docc#210

    Summary

    The --include-extended-types flag is transformed to the --emit-extension-block-symbols flag of the swift package dump-symbol-graph command. It is available starting from Swift 5.8.

    Dependencies

    All dependencies have been merged. For an overview see https://github.com/apple/swift-docc/issues/210#issuecomment-1312692921.

    Testing

    1. Use a toolchain generated from main or release/5.8 branches after December 21st
    2. Use the base branch of this PR when adding the swift-docc-plugin to your Package.swift:
    dependencies: [
        .package(url: "https://github.com/themomax/swift-docc-plugin", branch: "add-extended-types-flag")
    ]
    
    1. Add the --include-extended-types flag when running your command

    Verifying the basic functionality can be done with this sample repository. Running swift package --disable-sandbox preview-documentation --include-extended-types --target NestedTypes should produce the result shown below:

    image

    Checklist

    Make sure you check off the following items. If they cannot be completed, provide a reason.

    • [x] Added tests
    • [x] Ran the ./bin/test script and it succeeded: Swift 5.7.2: .bin/test succeeded Swift 5.8/main nightly: .bin/test succeeded after removing the --parallel flag from swift test invocations in the script (Running swift test --parallel on any package fails for me with an error similar to the one described here. However, this is an issue with the nightly toolchains I've been getting for a while now.)
    • [x] Updated documentation if necessary
    opened by theMomax 1
  • Support for binary targets

    Support for binary targets

    Feature Request: Support for binary targets

    Description:

    I make an xcframework, distributed as a SPM binary target. As far as I can tell, there is no way for me to incorporate DocC support for it directly in the package. I think it would be really nice to be able to incorporate documentation.

    Motivation:

    It is totally possible to get this to work out-of-band. But, especially with things like the Swift Package Index building and hosting documentation, finding a way to officially support it would be much more convenient. And, could also help encourage better documentation for binaries distributed this way.

    Importance:

    While my particular package is also open source, I think may binaries distributed this way are not. Encouraging better documentation for these cases would be really welcome.

    Alternatives Considered

    It is possible to get this to work with a custom solution, outside of SPM. But, its a pain, and doesn't work with existing tooling, particularly SPI.

    enhancement 
    opened by mattmassicotte 0
Releases(1.0.0)
Cordova-plugin-saveimage - This plugin helps you save images

cordova-plugin-saveimage This plugin helps you save images on iOS/Android Instal

Bernat 2 May 11, 2022
API surface for Swift plug-ins using the Swift Plugin Manager

SwiftPlugin The minimal API surface required for the Swift Plugin Manager to create instances from a loaded plugin. Additional documentation and refer

Joakim Hassila 2 Mar 25, 2022
PerFolderResourcesPublishPlugin - Per-folder resources plugin for the Publish package

Per-folder resources for Publish A Publish plugin that copies per-folder resourc

Tom Harrington 1 Feb 18, 2022
Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger.

MetalCompilerPlugin Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger. Description Swift Package Manag

Jonathan Wight 10 Oct 30, 2022
A VisionCamera Frame Processor plugin for fast buffer resizing

vision-camera-resize-plugin A VisionCamera Frame Processor Plugin for fast buffer resizing. By resizing buffers to a smaller resolution, you can achie

Marc Rousavy 16 Aug 10, 2022
This simple cordova plugin will download picture from an URL and save to IOS Photo Gallery.

Photo Viewer This plugin is intended to download a picture from an URL into IOS Photo library.. How to Install Cordova: cordova plugin add https://git

Alwin jose 1 Oct 23, 2021
Cordova plugin for detect screenshots and recordings

cordova-plugin-detect-screen-capture This plugin detects screen recording and screenshot events. The plugin will only work on devices with iOS >= 7 Su

Sasha 0 Nov 4, 2021
Cordova plugin to display a native color-picker dialog

Color Picker Plugin for Cordova (cordova-plugin-color-picker) Description This plugin allows you to display a color-picker native dialog in iOS and An

Antonio Vargas 1 May 10, 2022
Metazoom - A virtual camera plugin to pixellatedly share your screen

MetaZoom A virtual camera plugin to pixellatedly share your screen. See LICENSE.

Sahil Lavingia 22 Jan 4, 2023
Flutter openvpn - A new Flutter plugin that uses OpenVpn

flutter_openvpn A new Flutter plugin that uses OpenVpn. Installation Depend on i

Ferdi Gökdemir 0 Jan 8, 2022
Xcode plugin that moves the instruction pointer to the selected line

SFJumpToLine Xcode plugin that moves the instruction pointer to the selected line. Install: Install via Alcatraz Or clone and build the project, then

Simone Ferrini 9 Jan 14, 2021
Touch ID Plugin (Cordova) for iOS

cordova-plugin-gctouch-id Touch ID Plugin (Cordova) for iOS Author: Giulio Caruso aka rdn Index Description Technical Documentation Screenshots Adding

Giulio Caruso 20 Jan 3, 2022
Xcode plugin that brings ⇧⌘T from AppCode over to Xcode

Aviator An Xcode Plugin that brings ⇧⌘T over to Xcode This minimal plugin allows you to use the key combo ⇧⌘T to toggle between source and test files.

Mark Sands 29 Aug 18, 2018
An Xcode plugin for manually symbolicating crash logs

CrashSymbal An Xcode plugin for manually symbolicating crash logs Install Build the project to install the plugin. The plugin gets installed in /Libra

Julian F. Weinert 38 Jun 3, 2021
XcodeColorSense - An Xcode plugin that makes working with color easier.

XcodeColorSense An Xcode plugin that makes working with color easier. Inspired by ColorSense-for-Xcode with extra care for Hex color Features Show col

Khoa 77 Jul 1, 2022
A Xcode plugin to add highlight to the instances of selected symbol.

Auto Highlight Symbol About Xcode 8 Xcode 8 does't support plugins anymore, but there is a workaround, use at your own risk. Xcode can highlight insta

Nelson 83 Jan 3, 2023
An Xcode 7 plugin to build and run an app across multiple iOS devices with one click.

RunEverywhere Xcode Plugin Overview An Xcode 7 plugin to build and run an app across multiple iOS devices with one click. Gone are the days of manuall

Eric Mika 322 Sep 7, 2022
Xcode plugin to open the GitHub page of the commit of the currently selected line in the editor window.

Show in GitHub / BitBucket Xcode plugin to open a related Github or BitBucket page directly from the Xcode editor code window. Installs easily through

Lars Schneider 242 Jul 20, 2022
An Xcode plugin to improve dealing with colors in your project

Crayons is an Xcode7 plugin with various features that improve working with colors in your projects ##Code palettes (iOS only) You can share palettes

Fabio Ritrovato 477 Sep 23, 2022