SwiftPM has currently a bug, that products or targets of dependencies are taken into consideration when resolving names, regardless if they're used or not by the root package. This stops Swift PM from working on packages, that declare this package as a dependency and define their own TaskCLI target, as they collide with the definitions of this package. This is resolved, by prefixing TaskCLI with the package name. The product collision - which causes swift run - to run this package's task executable is resolved, by adding that product only temporarily during task execution using task.sh. See https://github.com/swiftlang/swift-package-manager/issues/8482
26 lines
810 B
Swift
26 lines
810 B
Swift
import _NIOFileSystem
|
|
|
|
public struct DoccFinder {
|
|
static let fileManager = FileSystem.shared
|
|
|
|
public static func hasDoccFolder(at path: String) async throws -> Bool {
|
|
let itemPath = FilePath(path)
|
|
var hasDoccFolder = false
|
|
|
|
try await withSubdirectories(at: itemPath) { subdirectory in
|
|
guard subdirectory.description.hasSuffix(".docc") else { return }
|
|
hasDoccFolder = true
|
|
}
|
|
return hasDoccFolder
|
|
}
|
|
|
|
private static func withSubdirectories(at path: FilePath, body: (FilePath) async throws -> Void) async throws {
|
|
let directoryHandle = try await fileManager.openDirectory(atPath: path)
|
|
for try await childContent in directoryHandle.listContents() {
|
|
guard childContent.type == .directory else { continue }
|
|
try await body(childContent.path)
|
|
}
|
|
try await directoryHandle.close()
|
|
}
|
|
}
|