From 61212cc1defc80362e060174381dc95d567361f4 Mon Sep 17 00:00:00 2001 From: Mattt Date: Thu, 25 Mar 2021 09:04:17 -0700 Subject: [PATCH 1/6] Include isDirectory key in file enumerator Skip hidden files and package descendents during file enumeration --- Sources/SwiftDoc/Module.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftDoc/Module.swift b/Sources/SwiftDoc/Module.swift index 0b09eb8d..889e040e 100644 --- a/Sources/SwiftDoc/Module.swift +++ b/Sources/SwiftDoc/Module.swift @@ -22,7 +22,7 @@ public final class Module { let fileManager = FileManager.default for path in paths { let directory = URL(fileURLWithPath: path) - guard let directoryEnumerator = fileManager.enumerator(at: directory, includingPropertiesForKeys: nil) else { continue } + guard let directoryEnumerator = fileManager.enumerator(at: directory, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else { continue } for case let url as URL in directoryEnumerator { var isDirectory: ObjCBool = false guard url.pathExtension == "swift", From 002922e62579dee646bdb2c8130f5eae65f80f22 Mon Sep 17 00:00:00 2001 From: Mattt Date: Thu, 25 Mar 2021 09:07:48 -0700 Subject: [PATCH 2/6] Skip top-level Tests directory --- Sources/SwiftDoc/Module.swift | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftDoc/Module.swift b/Sources/SwiftDoc/Module.swift index 889e040e..b95dc1b6 100644 --- a/Sources/SwiftDoc/Module.swift +++ b/Sources/SwiftDoc/Module.swift @@ -27,10 +27,22 @@ public final class Module { var isDirectory: ObjCBool = false guard url.pathExtension == "swift", fileManager.isReadableFile(atPath: url.path), - fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory), - isDirectory.boolValue == false - else { continue } - sources.append((url, directory)) + fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory) + else { + // Skip top-level Tests directory + if isDirectory.boolValue == true, + url.lastPathComponent == "Tests", + directory.appendingPathComponent("Tests").path == url.path + { + directoryEnumerator.skipDescendents() + } + + continue + } + + if isDirectory.boolValue == false { + sources.append((url, directory)) + } } } From 8567db1a105fb0c9210b44e99b89fd36a9b64101 Mon Sep 17 00:00:00 2001 From: Mattt Date: Thu, 25 Mar 2021 09:23:38 -0700 Subject: [PATCH 3/6] Update end-to-end tests to pass current directory as argument --- Tests/EndToEndTests/GenerateSubcommandTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/EndToEndTests/GenerateSubcommandTests.swift b/Tests/EndToEndTests/GenerateSubcommandTests.swift index ca9bdec6..dc2bcde4 100644 --- a/Tests/EndToEndTests/GenerateSubcommandTests.swift +++ b/Tests/EndToEndTests/GenerateSubcommandTests.swift @@ -13,7 +13,7 @@ final class GenerateSubcommandTests: XCTestCase { "--module-name", "SwiftDoc", "--format", "commonmark", "--output", outputDirectory.path, - "Sources" + "." ] ) { result in XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS) @@ -54,7 +54,7 @@ final class GenerateSubcommandTests: XCTestCase { "--module-name", "SwiftDoc", "--format", "html", "--output", outputDirectory.path, - "Sources" + "." ] ) { result in XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS) From 73964fcc76cd2e71a8d8d5d0fc8fdedbff1e236c Mon Sep 17 00:00:00 2001 From: Mattt Date: Thu, 25 Mar 2021 09:44:36 -0700 Subject: [PATCH 4/6] Add changelog entry for #229 --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 7eb28fcf..d20688ba 100644 --- a/Changelog.md +++ b/Changelog.md @@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed display of code declarations in HTML. #204 by @mattt. +- Changed the `generate` command to skip hidden files + and top-level `Tests` directories. + #229 by @mattt. ## [1.0.0-beta.5] - 2020-09-29 From 4ea9036fa8bab33983c2b8fb0762b684dee9fd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Thu, 25 Mar 2021 20:27:49 +0100 Subject: [PATCH 5/6] Use skipDescendants, which is available on Linux. --- Sources/SwiftDoc/Module.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftDoc/Module.swift b/Sources/SwiftDoc/Module.swift index b95dc1b6..aa9d2aaf 100644 --- a/Sources/SwiftDoc/Module.swift +++ b/Sources/SwiftDoc/Module.swift @@ -34,7 +34,7 @@ public final class Module { url.lastPathComponent == "Tests", directory.appendingPathComponent("Tests").path == url.path { - directoryEnumerator.skipDescendents() + directoryEnumerator.skipDescendants() } continue From a590cad4dbc232e377c61964a4e94d279b0cd6aa Mon Sep 17 00:00:00 2001 From: Mattt Date: Mon, 29 Mar 2021 05:31:59 -0700 Subject: [PATCH 6/6] Document new directory enumeration behavior in README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3cff9d4a..30b4da2d 100644 --- a/README.md +++ b/README.md @@ -107,13 +107,16 @@ $ apt-get install -y libxml2-dev graphviz be included. (default: public) -h, --help Show help information. -The `generate` subcommand +The `generate` subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. +Any hidden directories are skipped, +including `.git` and other directories with paths starting with a dot (`.`). +Top-level `Tests` directories are skipped as well. ```terminal -$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject +$ swift doc generate path/to/SwiftProject --module-name SwiftProject $ tree .build/documentation $ documentation/ ├── Home