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
Refactor to resolve some PR comments.
  • Loading branch information
emilyychenn committed May 21, 2024
commit 05b5e76ce0813880562adeca1d47e6ed87bedf3a
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,46 @@ extension CatalogTemplateKind {
"""
]
}

/// Content of the 'changeLog' template
static func changeLogTemplateFileContent(
frameworkName: String,
initialDocCArchiveVersion: String,
newerDocCArchiveVersion: String,
additionLinks: String,
removalLinks: String
) -> [String : String] {
[
"\(frameworkName.localizedCapitalized)_Changelog.md": """
# \(frameworkName.localizedCapitalized) Updates

@Metadata {
@PageColor(yellow)
}

Learn about important changes to \(frameworkName.localizedCapitalized).

## Overview

Browse notable changes in \(frameworkName.localizedCapitalized).

## Diff between \(initialDocCArchiveVersion) and \(newerDocCArchiveVersion)


### Change Log

#### Additions
_New symbols added in \(newerDocCArchiveVersion) that did not previously exist in \(initialDocCArchiveVersion)._

\(additionLinks)


#### Removals
_Old symbols that existed in \(initialDocCArchiveVersion) that no longer exist in \(newerDocCArchiveVersion)._

\(removalLinks)

"""
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,14 @@ extension Docc {

struct GenerateChangelog: ParsableCommand {

// MARK: - Content and Configuration
// MARK: - Configuration

/// Command line configuration.
static var configuration = CommandConfiguration(
commandName: "generate-changelog",
abstract: "Generate a changelog with symbol diffs between documentation archives ('.doccarchive' directories).",
shouldDisplay: true)

/// Content of the 'changeLog' template.
static func changeLogTemplateFileContent(
frameworkName: String,
initialDocCArchiveVersion: String,
newerDocCArchiveVersion: String,
additionLinks: String,
removalLinks: String
) -> [String : String] {
[
"\(frameworkName.localizedCapitalized)_Changelog.md": """
# \(frameworkName.localizedCapitalized) Updates

@Metadata {
@PageColor(yellow)
}

Learn about important changes to \(frameworkName.localizedCapitalized).

## Overview

Browse notable changes in \(frameworkName.localizedCapitalized).

## Diff between \(initialDocCArchiveVersion) and \(newerDocCArchiveVersion)


### Change Log

#### Additions
_New symbols added in \(newerDocCArchiveVersion) that did not previously exist in \(initialDocCArchiveVersion)._

\(additionLinks)


#### Removals
_Old symbols that existed in \(initialDocCArchiveVersion) that no longer exist in \(newerDocCArchiveVersion)._

\(removalLinks)

"""
]
}


// MARK: - Command Line Options & Arguments

Expand Down Expand Up @@ -115,37 +73,32 @@ extension Docc {
print("Showing ONLY high-level symbol diffs: modules, classes, protocols, and structs.")
}

let initialSet = Set(initialDocCArchiveAPIs.map { $0 })
let newSet = Set(newDocCArchiveAPIs.map { $0 })
let initialSet = Set(initialDocCArchiveAPIs)
let newSet = Set(newDocCArchiveAPIs)

// Compute additions and removals to both sets
let additionsToNewSet = newSet.subtracting(initialSet)
let removedFromOldSet = initialSet.subtracting(newSet)

// The framework name is the path component after "/documentation/".
var frameworkName: String = "No_Framework_Name"
var potentialFrameworkName = try findFrameworkName(initialPath: initialDocCArchivePath)
if potentialFrameworkName == nil {
potentialFrameworkName = try findFrameworkName(initialPath: newerDocCArchivePath)
}

if potentialFrameworkName != nil {
frameworkName = potentialFrameworkName ?? "No_Framework_Name"
}
let frameworkName: String = potentialFrameworkName ?? "No_Framework_Name"

let additionLinks = groupSymbols(symbolLinks: additionsToNewSet, frameworkName: frameworkName)
let removalLinks = groupSymbols(symbolLinks: removedFromOldSet, frameworkName: frameworkName)

// Create markdown file with changes in the newer DocC Archive that do not exist in the initial DocC Archive.
for fileNameAndContent in Docc.GenerateChangelog.changeLogTemplateFileContent(frameworkName: frameworkName, initialDocCArchiveVersion: initialArchiveName, newerDocCArchiveVersion: newerArchiveName, additionLinks: additionLinks, removalLinks: removalLinks) {
for fileNameAndContent in CatalogTemplateKind.changeLogTemplateFileContent(frameworkName: frameworkName, initialDocCArchiveVersion: initialArchiveName, newerDocCArchiveVersion: newerArchiveName, additionLinks: additionLinks, removalLinks: removalLinks) {
let fileName = fileNameAndContent.key
let content = fileNameAndContent.value
let filePath = initialDocCArchivePath.deletingLastPathComponent().appendingPathComponent(fileName)
try FileManager.default.createFile(at: filePath, contents: Data(content.utf8))
print("\nOutput file path: \(filePath)")
}
}


/// Pretty print all symbols' url identifiers into a pretty format, with a new line between each symbol.
func printAllSymbols(symbols: [URL]) {
Expand All @@ -154,7 +107,6 @@ extension Docc {
}
}


/// The framework name is the path component after "/documentation/".
func findFrameworkName(initialPath: URL) throws -> String? {
guard let enumerator = FileManager.default.enumerator(
Expand Down