Skip to content

Commit df019c0

Browse files
unnameddthomaspaulmann
authored andcommitted
Add path to README in the group if exists
1 parent ef1b8b1 commit df019c0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Tools/Toolkit/Sources/ToolkitLibrary/Core/Toolkit/Toolkit+ReadContent.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ extension Toolkit {
3333
group.subGroups = subGroups
3434
}
3535

36+
if let readmePath = pathForReadme(from: directory) {
37+
group.readme = readmePath
38+
}
39+
3640
if values.isEmpty == false || subGroups.isEmpty == false {
3741
parentGroups.append(group)
3842
}
3943
}
4044

4145
let directoryFiles = onlyFiles(at: path)
46+
4247
for file in directoryFiles where directoryFiles.isEmpty == false {
4348
guard ignoreFilesInDir == false else {
4449
continue
@@ -67,6 +72,27 @@ extension Toolkit {
6772
return scriptCommands
6873
}
6974

75+
func pathForReadme(from folderPath: AbsolutePath) -> String? {
76+
let directoryFiles = onlyFiles(at: folderPath)
77+
78+
for file in directoryFiles where directoryFiles.isEmpty == false {
79+
guard file.basenameWithoutExt.lowercased() == "readme" else {
80+
continue
81+
}
82+
83+
guard let fileContent = readContentFile(from: file), fileContent.count > 0 else {
84+
continue
85+
}
86+
87+
let pathCount = dataManager.extensionsPathString.count + 1
88+
let readmePath = file.pathString.dropFirst(pathCount)
89+
90+
return String(readmePath)
91+
}
92+
93+
return nil
94+
}
95+
7096
func readContentFile(from path: AbsolutePath) -> String? {
7197
guard let byteString = try? fileSystem.readFileContents(path) else {
7298
return nil
@@ -80,7 +106,7 @@ extension Toolkit {
80106

81107
func extractGitDates(from filePath: AbsolutePath) -> [String]? {
82108
do {
83-
let dates = try self.git.run(
109+
let dates = try git.run(
84110
"log", "--format=%aI", "--follow", filePath.basename,
85111
path: filePath
86112
)

Tools/Toolkit/Sources/ToolkitLibrary/Models/Group.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typealias Groups = [Group]
1010
struct Group: Codable {
1111
let name: String
1212
let path: String
13+
var readme: String?
1314
var scriptCommands: ScriptCommands = []
1415
var subGroups: Groups?
1516
}

0 commit comments

Comments
 (0)