44
55A package for generating documentation for Swift projects.
66
7- ** This project is under active development
8- and is expected to change significantly before its first stable release.**
9-
107Given a directory of Swift files,
11- ` swift-doc ` generates CommonMark (Markdown) files
8+ ` swift-doc ` generates HTML or CommonMark (Markdown) files
129for each class, structure, enumeration, and protocol
1310as well as top-level type aliases, functions, and variables.
1411
15- For an example of generated documentation,
16- [ check out the Wiki for our fork of Alamofire] [ alamofire wiki ] .
12+ ** Example Output**
1713
18- > ** Note** :
19- > Output is currently limited to CommonMark,
20- > but the plan is to support HTML and other formats as well.
14+ - [ HTML] [ swiftsemantics html ]
15+ - [ CommonMark / GitHub Wiki] [ alamofire wiki ]
2116
2217## Requirements
2318
@@ -54,18 +49,26 @@ collecting all Swift files into a single "module"
5449and generating documentation accordingly.
5550
5651``` terminal
57- $ swift doc generate path/to/SwiftProject/Sources --output Documentation
58- $ tree Documentation
59- $ Documentation /
52+ $ swift doc generate path/to/SwiftProject/Sources
53+ $ tree .build/documentation
54+ $ documentation /
6055├── Home
6156├── (...)
6257├── _Footer.md
6358└── _Sidebar.md
6459```
6560
6661By default,
67- output files are written to ` .build/documentation ` ,
68- but you can change that with the ` --output ` option flag.
62+ output files are written to ` .build/documentation `
63+ in CommonMark / GitHub Wiki format,
64+ but you can change that with the ` --output ` and ` --format ` option flags.
65+
66+ ``` terminal
67+ $ swift doc generate path/to/SwiftProject/Sources --output Documentation --format html
68+ $ Documentation/
69+ ├── (...)
70+ └── index.html
71+ ```
6972
7073#### swift-doc coverage
7174
@@ -178,114 +181,9 @@ jobs:
178181 with :
179182 path : " Documentation"
180183 env :
181- GITHUB_PERSONAL_ACCESS_TOKEN : ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
182- ` ` `
183-
184- * * *
185-
186- ## Motivation
187-
188- From its earliest days,
189- Swift has been fortunate to have [Jazzy][jazzy],
190- which is a fantastic tool for generating documentation
191- for both Swift and Objective-C projects.
192- Over time, however,
193- the way we write Swift code —
194- and indeed the language itself —
195- has evolved to incorporate patterns and features
196- that are difficult to understand using
197- the same documentation standards that served us well for Objective-C.
198-
199- Whereas in Objective-C,
200- you could get a complete view of a type's functionality from its class hierarchy,
201- Swift code today tends to layer and distribute functionality across
202- [a network of types][swift number protocols diagram].
203- While adopting a
204- [protocol-oriented paradigm][protocol-oriented programming]
205- can make Swift easier and more expressive to write,
206- it can also make Swift code more difficult to understand.
207-
208- Our primary goal for ` swift-doc`
209- is to make Swift documentation more useful
210- by surfacing the information you need to understand how an API works
211- and presenting it in a way that can be easily searched and accessed.
212- We want developers to be empowered to use Swift packages to their full extent,
213- without being reliant on (often outdated) blog posts or Stack Overflow threads.
214- We want documentation coverage to become as important as test coverage :
215- a valuable metric for code quality,
216- and an expected part of first-rate open source projects.
217-
218- Jazzy styles itself after Apple's official documentation circa 2014
219- (code-named "Jazz", as it were),
220- which was well-suited to understanding Swift code as we wrote it back then
221- when it was more similar to Objective-C.
222- But this design is less capable of documenting the behavior of
223- generically-constrained types,
224- default implementations,
225- [dynamic member lookup][se-0195],
226- [property wrappers][se-o258], or
227- [function builders][se-xxxx].
228- (Alas,
229- Apple's [most recent take][apple documentation] on reference documentation
230- hasn't improved matters,
231- having instead focused on perceived cosmetic issues.)
232-
233- Without much in the way of strong design guidance,
234- we're not entirely sure what Swift documentation _should_ look like.
235- But we do think plain text is a good place to start.
236- We look forward to
237- soliciting feedback and ideas from everyone
238- so that we can identify those needs
239- and figure out the best ways to meet them.
240-
241- In the meantime,
242- we've set ourselves up for success
243- by investing in the kind of foundation we'll need
244- to build whatever we decide best solves the problems at hand.
245- ` swift-doc` is built on top of a constellation of projects
246- that take advantage of modern infrastructure and tooling :
247-
248- - [SwiftSemantics][swiftsemantics] :
249- Parses Swift code into its constituent declarations
250- using [SwiftSyntax][swiftsyntax]
251- - [SwiftMarkup][swiftmarkup] :
252- Parses Swift documentation comments into structured entities
253- using [CommonMark][commonmark]
254- - [github-wiki-publish-action][github-wiki-publish-action] :
255- Publishes the contents of a directory to your project's wiki
256-
257- These new technologies have already yielded some promising results.
258- ` swift-doc` is built in Swift,
259- and can be installed on both macOS and Linux as a small, standalone binary.
260- Because it relies only on a syntactic reading of Swift source code,
261- without needing code first to be compiled,
262- ` swift-doc` is quite fast.
263- As a baseline,
264- compare its performance to Jazzy
265- when generating documentation for [SwiftSemantics][swiftsemantics] :
266-
267- ` ` ` terminal
268- $ cd SwiftSemantics
269-
270- $ time swift-doc Sources
271- 0.21 real 0.16 user 0.02 sys
272-
273- $ time jazzy # fresh build
274- jam out ♪♫ to your fresh new docs in ` docs`
275- 67.36 real 98.76 user 8.89 sys
276-
277-
278- $ time jazzy # with build cache
279- jam out ♪♫ to your fresh new docs in `docs`
280- 17.70 real 2.17 user 0.88 sys
184+ GH_PERSONAL_ACCESS_TOKEN : ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
281185` ` `
282186
283- Of course,
284- some of that is simply Jazzy doing more,
285- generating HTML, CSS, and a search index instead of just text.
286- Compare its [ generated HTML output] [ jazzy swiftsemantics ]
287- to [ a GitHub wiki generated with ` swift-doc ` ] [ swift-doc swiftsemantics ] .
288-
289187## License
290188
291189MIT
@@ -297,6 +195,7 @@ Mattt ([@mattt](https://twitter.com/mattt))
297195[ci badge]: https://github.com/SwiftDocOrg/swift-doc/workflows/CI/badge.svg
298196
299197[alamofire wiki]: https://github.com/SwiftDocOrg/Alamofire/wiki
198+ [swiftsemantics html]: https://swift-doc-preview.netlify.app
300199[github wiki]: https://help.github.com/en/github/building-a-strong-community/about-wikis
301200[github actions]: https://github.com/features/actions
302201[swiftsyntax]: https://github.com/apple/swift-syntax
0 commit comments