Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
commit aa59ef28ea56315eb421ba044ddaf0c4066bfff8 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Nov 7 10:26:28 2022 +0100 Add trailing carrier at the end of generated extension files commit e985950aa1e39d81d4938e15f8724c0f7723b003 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Fri Nov 4 16:37:34 2022 +0100 Replace installation script by script that install completion file Setup a Makefile to install resgen commit d574384c151259610a4c2f837b14068bb7716e44 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Fri Nov 4 14:33:39 2022 +0100 Refactor Improve testability Add tests on SwiftUI generated code Add tests on command commit d9e76632c3037da0ed9e1dd37056685416579da9 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:43:47 2022 +0100 Fixing bad merge on FontOptions commit 76b5ebfcd1cde7a7d4c83f516a4fc937841e7715 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:37:28 2022 +0100 Squashed commit of the following: commit 085f1ffc3347d3c48af91ffb00a1a9b381ce47d1 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Thu Nov 3 15:00:27 2022 +0100 Refactor SwiftUI extension generation and generation SwiftUI extension for images commit 4f7d7e18b138343a07cbb0bb47213818678ced6b Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Oct 31 16:21:32 2022 +0100 Génération de composant SwiftUI: Color et Image commit 0797667b2510f6fd45b9845f2d29c0c1e31da877 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Mon Oct 31 16:21:12 2022 +0100 Génération de composant SwiftUI: Color et Image commit 417a2630925841dd486ae1d684d28ab7dca240e0 Author: Thibaut Schmitt <t.schmitt@openium.fr> Date: Wed Oct 19 17:13:03 2022 +0200 Update Info.plist UIAppFonts key when generating fonts (if plist path if defined)
99 lines
3.7 KiB
Swift
99 lines
3.7 KiB
Swift
//
|
|
// Fonts.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 13/12/2021.
|
|
//
|
|
|
|
import ToolCore
|
|
import Foundation
|
|
import ArgumentParser
|
|
|
|
struct Fonts: ParsableCommand {
|
|
|
|
// MARK: - CommandConfiguration
|
|
|
|
static var configuration = CommandConfiguration(
|
|
abstract: "A utility to generate an helpful etension to access your custom font from code and also Info.plist UIAppsFont content.",
|
|
version: ResgenSwiftVersion
|
|
)
|
|
|
|
// MARK: - Static
|
|
|
|
static let toolName = "Fonts"
|
|
static let defaultExtensionName = "UIFont"
|
|
static let defaultExtensionNameSUI = "Font"
|
|
|
|
// MARK: - Command Options
|
|
|
|
@OptionGroup var options: FontsOptions
|
|
|
|
// MARK: - Run
|
|
|
|
public func run() throws {
|
|
print("[\(Self.toolName)] Starting fonts generation")
|
|
print("[\(Self.toolName)] Will use inputFile \(options.inputFile) to generate fonts")
|
|
|
|
// Check requirements
|
|
guard checkRequirements() else { return }
|
|
|
|
print("[\(Self.toolName)] Will generate fonts")
|
|
|
|
// Get fonts to generate
|
|
let fontsToGenerate = FontFileParser.parse(options.inputFile)
|
|
|
|
// Get real font names
|
|
let inputFolder = URL(fileURLWithPath: options.inputFile).deletingLastPathComponent().relativePath
|
|
let fontsNames = FontsToolHelper.getFontPostScriptName(for: fontsToGenerate,
|
|
inputFolder: inputFolder)
|
|
|
|
// Generate extension
|
|
FontExtensionGenerator.writeExtensionFile(fontsNames: fontsNames,
|
|
staticVar: options.staticMembers,
|
|
extensionName: options.extensionName,
|
|
extensionFilePath: options.extensionFilePath,
|
|
isSwiftUI: false)
|
|
|
|
FontExtensionGenerator.writeExtensionFile(fontsNames: fontsNames,
|
|
staticVar: options.staticMembers,
|
|
extensionName: options.extensionNameSwiftUI,
|
|
extensionFilePath: options.extensionFilePathSwiftUI,
|
|
isSwiftUI: true)
|
|
|
|
print("Info.plist has been updated with:")
|
|
print("\(FontPlistGenerator.generatePlistUIAppsFontContent(for: fontsNames, infoPlistPaths: options.infoPlistPaths))")
|
|
|
|
print("[\(Self.toolName)] Fonts generated")
|
|
}
|
|
|
|
// MARK: - Requirements
|
|
|
|
private func checkRequirements() -> Bool {
|
|
let fileManager = FileManager()
|
|
|
|
// Check input file exists
|
|
guard fileManager.fileExists(atPath: options.inputFile) else {
|
|
let error = FontsToolError.fileNotExists(options.inputFile)
|
|
print(error.localizedDescription)
|
|
Fonts.exit(withError: error)
|
|
}
|
|
|
|
// Extension for UIKit and SwiftUI should have different name
|
|
guard options.extensionName != options.extensionNameSwiftUI else {
|
|
let error = FontsToolError.extensionNamesCollision(options.extensionName)
|
|
print(error.localizedDescription)
|
|
Fonts.exit(withError: error)
|
|
}
|
|
|
|
// Check if needed to regenerate
|
|
guard GeneratorChecker.shouldGenerate(force: options.forceGeneration,
|
|
inputFilePath: options.inputFile,
|
|
extensionFilePath: options.extensionFilePath) else {
|
|
print("[\(Self.toolName)] Fonts are already up to date :) ")
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
}
|