Skip to content

Commit a21dba3

Browse files
committed
Resolve PR comments.
1 parent a099b9a commit a21dba3

File tree

2 files changed

+47
-53
lines changed

2 files changed

+47
-53
lines changed

Sources/SwiftDocCUtilities/Action/Actions/Init/CatalogTemplateKind.swift

+42
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,46 @@ extension CatalogTemplateKind {
8787
"""
8888
]
8989
}
90+
91+
/// Content of the 'changeLog' template
92+
static func changeLogTemplateFileContent(
93+
frameworkName: String,
94+
initialDocCArchiveVersion: String,
95+
newerDocCArchiveVersion: String,
96+
additionLinks: String,
97+
removalLinks: String
98+
) -> [String : String] {
99+
[
100+
"\(frameworkName.localizedCapitalized)_Changelog.md": """
101+
# \(frameworkName.localizedCapitalized) Updates
102+
103+
@Metadata {
104+
@PageColor(yellow)
105+
}
106+
107+
Learn about important changes to \(frameworkName.localizedCapitalized).
108+
109+
## Overview
110+
111+
Browse notable changes in \(frameworkName.localizedCapitalized).
112+
113+
## Diff between \(initialDocCArchiveVersion) and \(newerDocCArchiveVersion)
114+
115+
116+
### Change Log
117+
118+
#### Additions
119+
_New symbols added in \(newerDocCArchiveVersion) that did not previously exist in \(initialDocCArchiveVersion)._
120+
121+
\(additionLinks)
122+
123+
124+
#### Removals
125+
_Old symbols that existed in \(initialDocCArchiveVersion) that no longer exist in \(newerDocCArchiveVersion)._
126+
127+
\(removalLinks)
128+
129+
"""
130+
]
131+
}
90132
}

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/GenerateChangeLog.swift

+5-53
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,14 @@ extension Docc {
1616

1717
struct GenerateChangelog: ParsableCommand {
1818

19-
// MARK: - Content and Configuration
19+
// MARK: - Configuration
2020

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

27-
/// Content of the 'changeLog' template.
28-
static func changeLogTemplateFileContent(
29-
frameworkName: String,
30-
initialDocCArchiveVersion: String,
31-
newerDocCArchiveVersion: String,
32-
additionLinks: String,
33-
removalLinks: String
34-
) -> [String : String] {
35-
[
36-
"\(frameworkName.localizedCapitalized)_Changelog.md": """
37-
# \(frameworkName.localizedCapitalized) Updates
38-
39-
@Metadata {
40-
@PageColor(yellow)
41-
}
42-
43-
Learn about important changes to \(frameworkName.localizedCapitalized).
44-
45-
## Overview
46-
47-
Browse notable changes in \(frameworkName.localizedCapitalized).
48-
49-
## Diff between \(initialDocCArchiveVersion) and \(newerDocCArchiveVersion)
50-
51-
52-
### Change Log
53-
54-
#### Additions
55-
_New symbols added in \(newerDocCArchiveVersion) that did not previously exist in \(initialDocCArchiveVersion)._
56-
57-
\(additionLinks)
58-
59-
60-
#### Removals
61-
_Old symbols that existed in \(initialDocCArchiveVersion) that no longer exist in \(newerDocCArchiveVersion)._
62-
63-
\(removalLinks)
64-
65-
"""
66-
]
67-
}
68-
6927

7028
// MARK: - Command Line Options & Arguments
7129

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

118-
let initialSet = Set(initialDocCArchiveAPIs.map { $0 })
119-
let newSet = Set(newDocCArchiveAPIs.map { $0 })
76+
let initialSet = Set(initialDocCArchiveAPIs)
77+
let newSet = Set(newDocCArchiveAPIs)
12078

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

12583
// The framework name is the path component after "/documentation/".
126-
var frameworkName: String = "No_Framework_Name"
12784
var potentialFrameworkName = try findFrameworkName(initialPath: initialDocCArchivePath)
12885
if potentialFrameworkName == nil {
12986
potentialFrameworkName = try findFrameworkName(initialPath: newerDocCArchivePath)
13087
}
131-
132-
if potentialFrameworkName != nil {
133-
frameworkName = potentialFrameworkName ?? "No_Framework_Name"
134-
}
88+
let frameworkName: String = potentialFrameworkName ?? "No_Framework_Name"
13589

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

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

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

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

0 commit comments

Comments
 (0)