resgen.swift/Sources/ResgenSwift/Fonts/Generator/FontPlistGenerator.swift
Thibaut Schmitt ae7c0abbc2
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Fix plist font file name and fix all tests
2025-04-30 11:37:17 +02:00

45 lines
1.5 KiB
Swift

//
// FontPlistGenerator.swift
//
//
// Created by Thibaut Schmitt on 29/08/2022.
//
import Foundation
import ToolCore
class FontPlistGenerator {
static func generatePlistUIAppsFontContent(for fonts: [FontName], infoPlistPaths: [String]) -> String {
let fontsToAddToPlist = fonts
.compactMap { $0 }
// Update each plist
infoPlistPaths.forEach { infoPlist in
// Remove UIAppFonts value
Shell.shell(launchPath: "/usr/libexec/PlistBuddy",
["-c", "delete :UIAppFonts", infoPlist])
// Add UIAppFonts empty array
debugPrint("Will PlistBuddy -c add :UIAppFonts array \(infoPlist)")
Shell.shell(launchPath: "/usr/libexec/PlistBuddy",
["-c", "add :UIAppFonts array", infoPlist])
// Fill array with fonts
fontsToAddToPlist
.forEach { fontName in
Shell.shell(launchPath: "/usr/libexec/PlistBuddy",
["-c", "add :UIAppFonts: string \(fontName.filename).\(fontName.fileExtension)", infoPlist])
}
}
var plistData = "<key>UIAppFonts</key>\n\t<array>\n"
fontsToAddToPlist
.forEach { fontName in
plistData += "\t\t<string>\(fontName.filename).\(fontName.fileExtension)</string>\n"
}
plistData += "\t</array>"
return plistData
}
}