@@ -13,6 +13,7 @@ import Foundation
13
13
import SwiftDocC
14
14
15
15
extension Docc . ProcessArchive {
16
+
16
17
struct DiffDocCArchive : ParsableCommand {
17
18
18
19
// MARK: - Configuration
@@ -42,21 +43,48 @@ extension Docc.ProcessArchive {
42
43
43
44
public mutating func run( ) throws {
44
45
45
- let initialDocCArchiveAPIs : [ String ] = try findAllSymbols ( initialPath: initialDocCArchivePath)
46
- let newDocCArchiveAPIs : [ String ] = try findAllSymbols ( initialPath: newerDocCArchivePath)
46
+ // Process arguments to start from the /data/ subdirectory.
47
+ // This is where all the relevant renderJSON are contained.
48
+ let initialProcessedArchivePath = initialDocCArchivePath. appendingPathComponent ( " data " )
49
+ let newerProcessedArchivePath = newerDocCArchivePath. appendingPathComponent ( " data " )
50
+
51
+ let initialDocCArchiveAPIs : [ URL ] = try findAllSymbolLinks ( initialPath: initialProcessedArchivePath)
52
+ let newDocCArchiveAPIs : [ URL ] = try findAllSymbolLinks ( initialPath: newerProcessedArchivePath)
47
53
48
54
print ( " \n initialDocCArchiveAPIs: " )
49
55
print ( initialDocCArchiveAPIs)
50
56
51
57
print ( " \n newDocCArchiveAPIs: " )
52
58
print ( newDocCArchiveAPIs)
53
59
54
- let initialSet = Set ( initialDocCArchiveAPIs. map { $0. plainText } )
55
- let newSet = Set ( newDocCArchiveAPIs. map { $0. plainText } )
60
+ let initialSet = Set ( initialDocCArchiveAPIs. map { $0 } )
61
+ let newSet = Set ( newDocCArchiveAPIs. map { $0 } )
56
62
let difference = newSet. subtracting ( initialSet)
57
63
print ( " \n Difference: \n \( difference) " )
58
64
}
59
65
66
+ // Given a URL, return each of the symbols by their unique identifying links
67
+ func findAllSymbolLinks( initialPath: URL ) throws -> [ URL ] {
68
+ guard let enumerator = FileManager . default. enumerator (
69
+ at: initialPath,
70
+ includingPropertiesForKeys: [ ] ,
71
+ options: . skipsHiddenFiles,
72
+ errorHandler: nil
73
+ ) else {
74
+ return [ ]
75
+ }
76
+
77
+ var returnSymbolLinks : [ URL ] = [ ]
78
+ for case let filePath as URL in enumerator {
79
+ if filePath. lastPathComponent. hasSuffix ( " .json " ) {
80
+ let symbolLink = try findSymbolLink ( symbolPath: filePath)
81
+ returnSymbolLinks. append ( symbolLink)
82
+ }
83
+ }
84
+
85
+ return returnSymbolLinks
86
+ }
87
+
60
88
func findAllSymbols( initialPath: URL ) throws -> [ String ] {
61
89
guard let enumerator = FileManager . default. enumerator (
62
90
at: initialPath,
@@ -76,6 +104,15 @@ extension Docc.ProcessArchive {
76
104
77
105
return returnSymbols
78
106
}
107
+
108
+ // Given a file path to a renderJSON, return that symbol's url from its identifier.
109
+ func findSymbolLink( symbolPath: URL ) throws -> URL {
110
+ let renderJSONData = try Data ( contentsOf: symbolPath)
111
+ let decoder = RenderJSONDecoder . makeDecoder ( )
112
+ let renderNode = try decoder. decode ( RenderNode . self, from: renderJSONData)
113
+
114
+ return renderNode. identifier. url
115
+ }
79
116
80
117
}
81
118
}
0 commit comments