Skip to content

Commit 7c4a4d2

Browse files
committed
Diff now returns all symbols as links.
1 parent e8beb53 commit 7c4a4d2

File tree

1 file changed

+41
-4
lines changed
  • Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands

1 file changed

+41
-4
lines changed

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/File.swift

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Foundation
1313
import SwiftDocC
1414

1515
extension Docc.ProcessArchive {
16+
1617
struct DiffDocCArchive: ParsableCommand {
1718

1819
// MARK: - Configuration
@@ -42,21 +43,48 @@ extension Docc.ProcessArchive {
4243

4344
public mutating func run() throws {
4445

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)
4753

4854
print("\ninitialDocCArchiveAPIs: ")
4955
print(initialDocCArchiveAPIs)
5056

5157
print("\nnewDocCArchiveAPIs: ")
5258
print(newDocCArchiveAPIs)
5359

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 })
5662
let difference = newSet.subtracting(initialSet)
5763
print("\nDifference:\n\(difference)")
5864
}
5965

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+
6088
func findAllSymbols(initialPath: URL) throws -> [String] {
6189
guard let enumerator = FileManager.default.enumerator(
6290
at: initialPath,
@@ -76,6 +104,15 @@ extension Docc.ProcessArchive {
76104

77105
return returnSymbols
78106
}
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+
}
79116

80117
}
81118
}

0 commit comments

Comments
 (0)