Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Improve file enumeration in generate subcommand #229

Merged
merged 6 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
mattt marked this conversation as resolved.
Show resolved Hide resolved
#229 by @mattt.

## [1.0.0-beta.5] - 2020-09-29

Expand Down
22 changes: 17 additions & 5 deletions Sources/SwiftDoc/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ 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",
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()
mattt marked this conversation as resolved.
Show resolved Hide resolved
}

continue
}

if isDirectory.boolValue == false {
sources.append((url, directory))
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/EndToEndTests/GenerateSubcommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class GenerateSubcommandTests: XCTestCase {
"--module-name", "SwiftDoc",
"--format", "commonmark",
"--output", outputDirectory.path,
"Sources"
"."
]
) { result in
XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS)
Expand Down Expand Up @@ -54,7 +54,7 @@ final class GenerateSubcommandTests: XCTestCase {
"--module-name", "SwiftDoc",
"--format", "html",
"--output", outputDirectory.path,
"Sources"
"."
]
) { result in
XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS)
Expand Down