feat(RES-34): Fix plist font filename (#14)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
Reviewed-on: #14
This commit is contained in:
@ -8,37 +8,44 @@
|
||||
import Foundation
|
||||
import ToolCore
|
||||
|
||||
class FontPlistGenerator {
|
||||
enum 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])
|
||||
|
||||
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])
|
||||
Shell.shell(
|
||||
launchPath: "/usr/libexec/PlistBuddy",
|
||||
["-c", "add :UIAppFonts array", infoPlist]
|
||||
)
|
||||
|
||||
// Fill array with fonts
|
||||
fontsToAddToPlist
|
||||
.forEach {
|
||||
Shell.shell(launchPath: "/usr/libexec/PlistBuddy",
|
||||
["-c", "add :UIAppFonts: string \($0)", infoPlist])
|
||||
.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 {
|
||||
plistData += "\t\t<string>\($0)</string>\n"
|
||||
.forEach { fontName in
|
||||
plistData += "\t\t<string>\(fontName.filename).\(fontName.fileExtension)</string>\n"
|
||||
}
|
||||
plistData += "\t</array>"
|
||||
|
||||
|
||||
return plistData
|
||||
}
|
||||
}
|
||||
|
@ -8,45 +8,51 @@
|
||||
import Foundation
|
||||
import ToolCore
|
||||
|
||||
class FontExtensionGenerator {
|
||||
enum FontExtensionGenerator {
|
||||
|
||||
private static func getFontNameEnum(fontsNames: [String]) -> String {
|
||||
private static func getFontNameEnum(fontsNames: [FontName]) -> String {
|
||||
var enumDefinition = " enum FontName: String {\n"
|
||||
|
||||
|
||||
fontsNames.forEach {
|
||||
enumDefinition += " case \($0.fontNameSanitize) = \"\($0)\"\n"
|
||||
enumDefinition += " case \($0.fontNameSanitize) = \"\($0.postscriptName)\"\n"
|
||||
}
|
||||
enumDefinition += " }\n"
|
||||
|
||||
|
||||
return enumDefinition
|
||||
}
|
||||
|
||||
static func writeExtensionFile(fontsNames: [String],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool) {
|
||||
|
||||
static func writeExtensionFile(
|
||||
fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool
|
||||
) {
|
||||
// Create extension content
|
||||
let extensionContent = Self.getExtensionContent(fontsNames: fontsNames,
|
||||
staticVar: staticVar,
|
||||
extensionName: extensionName,
|
||||
isSwiftUI: isSwiftUI)
|
||||
|
||||
let extensionContent = Self.getExtensionContent(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: staticVar,
|
||||
extensionName: extensionName,
|
||||
isSwiftUI: isSwiftUI
|
||||
)
|
||||
|
||||
// Write content
|
||||
let extensionFilePathURL = URL(fileURLWithPath: extensionFilePath)
|
||||
do {
|
||||
try extensionContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8)
|
||||
} catch let error {
|
||||
} catch {
|
||||
let error = FontsToolError.writeExtension(extensionFilePath, error.localizedDescription)
|
||||
print(error.description)
|
||||
Fonts.exit(withError: error)
|
||||
}
|
||||
}
|
||||
|
||||
static func getExtensionContent(fontsNames: [String],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool) -> String {
|
||||
|
||||
static func getExtensionContent(
|
||||
fontsNames: [FontName],
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI),
|
||||
Self.getFontNameEnum(fontsNames: fontsNames),
|
||||
@ -55,34 +61,34 @@ class FontExtensionGenerator {
|
||||
]
|
||||
.joined(separator: "\n")
|
||||
}
|
||||
|
||||
|
||||
private static func getHeader(extensionClassname: String, isSwiftUI: Bool) -> String {
|
||||
"""
|
||||
// Generated by ResgenSwift.\(Fonts.toolName) \(ResgenSwiftVersion)
|
||||
|
||||
|
||||
import \(isSwiftUI ? "SwiftUI" : "UIKit")
|
||||
|
||||
|
||||
extension \(extensionClassname) {\n
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
private static func getFontMethods(fontsNames: [FontName], staticVar: Bool, isSwiftUI: Bool) -> String {
|
||||
let pragma = " // MARK: - Getter"
|
||||
|
||||
|
||||
var propertiesOrMethods: [String] = fontsNames
|
||||
.unique()
|
||||
.map {
|
||||
$0.getProperty(isStatic: staticVar, isSwiftUI: isSwiftUI)
|
||||
}
|
||||
|
||||
|
||||
propertiesOrMethods.insert(pragma, at: 0)
|
||||
return propertiesOrMethods.joined(separator: "\n\n")
|
||||
}
|
||||
|
||||
|
||||
private static func getFooter() -> String {
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user