Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Diff two DocC Archives to produce three lists: (1) The existing symbo…
…ls within the first DocC Archive, (2) The existing symbols within the second DocC Archive, and (3) The new symbols added to the second DocC Archive that did not exist in the first DocC Archive
  • Loading branch information
emilyychenn committed May 21, 2024
commit 7ac8ec7ab61abd89ba97985acf9080662c68b2bb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import Foundation
import SwiftDocC

extension Docc.ProcessArchive {
struct Diff: ParsableCommand {
struct DiffRenderJSON: ParsableCommand {

// MARK: - Configuration

static var configuration = CommandConfiguration(
commandName: "diff",
commandName: "diff-render-json",
abstract: "Produce the symbol diff between two Render JSON files.",
shouldDisplay: true)

Expand Down
81 changes: 81 additions & 0 deletions Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/File.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import ArgumentParser
import Foundation
import SwiftDocC

extension Docc.ProcessArchive {
struct DiffDocCArchive: ParsableCommand {

// MARK: - Configuration

static var configuration = CommandConfiguration(
commandName: "diff-docc-archive",
abstract: "Produce a list of symbols added in the newer DocC Archive that did not exist in the initial DocC Archive.",
shouldDisplay: true)

// MARK: - Command Line Options & Arguments

@Argument(
help: ArgumentHelp(
"The path to the initial DocC Archive to be compared.",
valueName: "initialDocCArchive"),
transform: URL.init(fileURLWithPath:))
var initialDocCArchivePath: URL

@Argument(
help: ArgumentHelp(
"The path to the newer DocC Archive to be compared.",
valueName: "newerDocCArchive"),
transform: URL.init(fileURLWithPath:))
var newerDocCArchivePath: URL

// MARK: - Execution

public mutating func run() throws {

let initialDocCArchiveAPIs: [String] = try findAllSymbols(initialPath: initialDocCArchivePath)
let newDocCArchiveAPIs: [String] = try findAllSymbols(initialPath: newerDocCArchivePath)

print("\ninitialDocCArchiveAPIs: ")
print(initialDocCArchiveAPIs)

print("\nnewDocCArchiveAPIs: ")
print(newDocCArchiveAPIs)

let initialSet = Set(initialDocCArchiveAPIs.map { $0.plainText })
let newSet = Set(newDocCArchiveAPIs.map { $0.plainText })
let difference = newSet.subtracting(initialSet)
print("\nDifference:\n\(difference)")
}

func findAllSymbols(initialPath: URL) throws -> [String] {
guard let enumerator = FileManager.default.enumerator(
at: initialPath,
includingPropertiesForKeys: [],
options: .skipsHiddenFiles,
errorHandler: nil
) else {
return []
}

var returnSymbols: [String] = []
for case let filePath as URL in enumerator {
if filePath.lastPathComponent.hasSuffix(".json") {
returnSymbols.append(filePath.lastPathComponent)
}
}

return returnSymbols
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Docc {
static var configuration = CommandConfiguration(
commandName: "process-archive",
abstract: "Perform operations on documentation archives ('.doccarchive' directories).",
subcommands: [TransformForStaticHosting.self, Index.self, Diff.self])
subcommands: [TransformForStaticHosting.self, Index.self, DiffRenderJSON.self, DiffDocCArchive.self])

}
}