Optional generation of extension (R.xx)
Optional generation of Colors/Fonts/Images/Stringium extension Fix swiftlint warning
This commit is contained in:
@ -18,20 +18,20 @@ struct FontsOptions: ParsableArguments {
|
||||
@Argument(help: "Input files where fonts ared defined.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
var inputFile: String
|
||||
|
||||
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
var extensionOutputPath: String
|
||||
|
||||
@Option(help: "Tell if it will generate static properties or methods")
|
||||
var staticMembers: Bool = false
|
||||
|
||||
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
var extensionOutputPath: String
|
||||
|
||||
@Option(help: "Extension name. If not specified, it will generate an Font extension.")
|
||||
var extensionName: String = Fonts.defaultExtensionName
|
||||
|
||||
@Option(help: "Extension name. If not specified, it will generate an UIFont extension.")
|
||||
var extensionNameUIKit: String = Fonts.defaultExtensionNameUIKit
|
||||
@Option(help: "Extension name. If not specified, no extension will be generated.")
|
||||
var extensionNameUIKit: String?
|
||||
|
||||
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+FontsMyApp.swift")
|
||||
var extensionSuffix: String = ""
|
||||
var extensionSuffix: String?
|
||||
|
||||
@Option(name: .customLong("info-plist-paths"), help: "Info.plist paths (array). Will be used to update UIAppFonts content")
|
||||
fileprivate var infoPlistPathsRaw: String = ""
|
||||
@ -44,7 +44,7 @@ extension FontsOptions {
|
||||
// MARK: - SwiftUI
|
||||
|
||||
var extensionFileName: String {
|
||||
if extensionSuffix.isEmpty == false {
|
||||
if let extensionSuffix {
|
||||
return "\(extensionName)+\(extensionSuffix).swift"
|
||||
}
|
||||
return "\(extensionName).swift"
|
||||
@ -56,15 +56,19 @@ extension FontsOptions {
|
||||
|
||||
// MARK: - UIKit
|
||||
|
||||
var extensionFileNameUIKit: String {
|
||||
if extensionSuffix.isEmpty == false {
|
||||
var extensionFileNameUIKit: String? {
|
||||
guard let extensionNameUIKit else { return nil }
|
||||
|
||||
if let extensionSuffix {
|
||||
return "\(extensionNameUIKit)+\(extensionSuffix).swift"
|
||||
}
|
||||
return "\(extensionNameUIKit).swift"
|
||||
}
|
||||
|
||||
var extensionFilePathUIKit: String {
|
||||
"\(extensionOutputPath)/\(extensionFileNameUIKit)"
|
||||
var extensionFilePathUIKit: String? {
|
||||
guard let extensionFileNameUIKit else { return nil }
|
||||
|
||||
return "\(extensionOutputPath)/\(extensionFileNameUIKit)"
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
@ -22,7 +22,6 @@ struct Fonts: ParsableCommand {
|
||||
|
||||
static let toolName = "Fonts"
|
||||
static let defaultExtensionName = "Font"
|
||||
static let defaultExtensionNameUIKit = "UIFont"
|
||||
|
||||
// MARK: - Command Options
|
||||
|
||||
@ -61,16 +60,25 @@ struct Fonts: ParsableCommand {
|
||||
isSwiftUI: true
|
||||
)
|
||||
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: options.extensionNameUIKit,
|
||||
extensionFilePath: options.extensionFilePathUIKit,
|
||||
isSwiftUI: false
|
||||
)
|
||||
if let extensionNameUIKit = options.extensionNameUIKit,
|
||||
let extensionFilePathUIKit = options.extensionFilePathUIKit {
|
||||
FontExtensionGenerator.writeExtensionFile(
|
||||
fontsNames: fontsNames,
|
||||
staticVar: options.staticMembers,
|
||||
extensionName: extensionNameUIKit,
|
||||
extensionFilePath: extensionFilePathUIKit,
|
||||
isSwiftUI: false
|
||||
)
|
||||
}
|
||||
|
||||
print("Info.plist has been updated with:")
|
||||
print("\(FontPlistGenerator.generatePlistUIAppsFontContent(for: fontsNames, infoPlistPaths: options.infoPlistPaths))")
|
||||
if options.infoPlistPaths.isEmpty == false {
|
||||
let plistUpdateFontsData = FontPlistGenerator.generatePlistUIAppsFontContent(
|
||||
for: fontsNames,
|
||||
infoPlistPaths: options.infoPlistPaths
|
||||
)
|
||||
print("Info.plist has been updated with:")
|
||||
print(plistUpdateFontsData)
|
||||
}
|
||||
|
||||
print("[\(Self.toolName)] Fonts generated")
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ enum FontsToolError: Error {
|
||||
case inputFolderNotFound(String)
|
||||
case fileNotExists(String)
|
||||
case writeExtension(String, String)
|
||||
case missingExtensionPath
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
@ -31,6 +32,9 @@ enum FontsToolError: Error {
|
||||
|
||||
case let .writeExtension(filename, info):
|
||||
return "error: [\(Fonts.toolName)] An error occured while writing extension in \(filename): \(info)"
|
||||
|
||||
case .missingExtensionPath:
|
||||
return "error: [\(Fonts.toolName)] Extension need to be generated but no `extensionOutputPath` is provided"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user