@@ -10,8 +10,7 @@ let moduleList = CommandLine.arguments[2]
10
10
11
11
let modules = moduleList. components ( separatedBy: " , " )
12
12
13
- let currentDirectoryUrl = URL ( fileURLWithPath: FileManager . default. currentDirectoryPath, isDirectory: true )
14
- let publicDirectoryUrl = currentDirectoryUrl. appendingPathComponent ( " public " , isDirectory: true )
13
+ let publicDirectoryUrl = URL . currentDirectory ( ) . appending ( component: " public/ " )
15
14
16
15
try run ( )
17
16
@@ -34,7 +33,7 @@ func run() throws {
34
33
}
35
34
36
35
func ensurePluginAvailable( ) throws {
37
- let manifestUrl = currentDirectoryUrl . appendingPathComponent ( " Package.swift " , isDirectory : false )
36
+ let manifestUrl = URL . currentDirectory ( ) . appending ( component : " Package.swift " )
38
37
var manifestContents = try String ( contentsOf: manifestUrl, encoding: . utf8)
39
38
if !manifestContents. contains ( " .package(url: \" https://github.com/apple/swift-docc-plugin " ) {
40
39
// This is freely admitted to be quick and dirty. When SE-0301 gets into a release, we can use that.
@@ -54,7 +53,7 @@ func ensurePluginAvailable() throws {
54
53
func generateDocs( module: String ) throws {
55
54
print ( " 🔎 Finding DocC catalog " )
56
55
let doccCatalogs = try FileManager . default. contentsOfDirectory (
57
- at: currentDirectoryUrl . appendingPathComponent ( " Sources " , isDirectory : true ) . appendingPathComponent ( module, isDirectory : true ) ,
56
+ at: URL . currentDirectory ( ) . appending ( components : " Sources " , " \ ( module) / " ) ,
58
57
includingPropertiesForKeys: nil ,
59
58
options: [ . skipsSubdirectoryDescendants]
60
59
) . filter { $0. hasDirectoryPath && $0. pathExtension == " docc " }
@@ -72,8 +71,8 @@ func generateDocs(module: String) throws {
72
71
print ( " 📐 Copying theme " )
73
72
do {
74
73
try FileManager . default. copyItemIfExistsWithoutOverwrite (
75
- at: currentDirectoryUrl . appendingPathComponent ( " theme-settings.json " , isDirectory : false ) ,
76
- to: doccCatalogUrl. appendingPathComponent ( " theme-settings.json " , isDirectory : false )
74
+ at: URL . currentDirectory ( ) . appending ( component : " theme-settings.json " ) ,
75
+ to: doccCatalogUrl. appending ( component : " theme-settings.json " )
77
76
)
78
77
} catch CocoaError . fileReadNoSuchFile , CocoaError. fileWriteFileExists {
79
78
// ignore
@@ -92,7 +91,7 @@ func generateDocs(module: String) throws {
92
91
" --fallback-bundle-version " , " 1.0.0 " ,
93
92
" --transform-for-static-hosting " ,
94
93
" --hosting-base-path " , " / \( module. lowercased ( ) ) " ,
95
- " --output-path " , publicDirectoryUrl. appendingPathComponent ( module. lowercased ( ) , isDirectory : true ) . path,
94
+ " --output-path " , publicDirectoryUrl. appending ( component : " \( module. lowercased ( ) ) / " ) . path,
96
95
] )
97
96
}
98
97
@@ -111,7 +110,7 @@ func shell(_ args: [String]) throws {
111
110
}
112
111
113
112
// Run the command:
114
- let task = try Process . run ( URL ( fileURLWithPath : " /usr/bin/env " , isDirectory : false ) , arguments: args)
113
+ let task = try Process . run ( URL ( filePath : " /usr/bin/env " ) , arguments: args)
115
114
task. waitUntilExit ( )
116
115
guard task. terminationStatus == 0 else {
117
116
throw ShellError ( terminationStatus: task. terminationStatus)
@@ -141,3 +140,23 @@ extension FileManager {
141
140
}
142
141
}
143
142
}
143
+
144
+ #if !canImport(Darwin)
145
+ extension URL {
146
+ public enum DirectoryHint : Equatable { case isDirectory, notDirectory, inferFromPath }
147
+ static func isDirFlag( _ path: some StringProtocol , _ hint: DirectoryHint ) -> Bool {
148
+ hint == . inferFromPath ? path. last == " / " : hint == . isDirectory
149
+ }
150
+ public init ( filePath: String , directoryHint hint: DirectoryHint = . inferFromPath, relativeTo base: URL ? = nil ) {
151
+ self = URL ( fileURLWithPath: filePath, isDirectory: Self . isDirFlag ( path, hint) , relativeTo: base)
152
+ }
153
+ public func appending( component: some StringProtocol , directoryHint hint: DirectoryHint = . inferFromPath) -> URL {
154
+ self . appendingPathComponent ( component, isDirectory: Self . isDirFlag ( component, hint) )
155
+ }
156
+ public func appending( components: ( some StringProtocol ) ... , directoryHint hint: DirectoryHint = . inferFromPath) -> URL {
157
+ components. dropLast ( ) . reduce ( self ) { $0. appending ( component: $1, directoryHint: . isDirectory) }
158
+ . appending ( component: components. last!, directoryHint: hint)
159
+ }
160
+ public static func currentDirectory( ) -> URL { . init( filePath: FileManager . default. currentDirectoryPath, directoryHint: . isDirectory) }
161
+ }
162
+ #endif
0 commit comments