feat(RES-34): Fix plist font filename (#14)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good

Reviewed-on: #14
This commit is contained in:
2025-05-05 09:53:05 +02:00
parent 8442c89944
commit 756de4f1de
96 changed files with 3028 additions and 2852 deletions

View File

@ -1,96 +1,117 @@
//
// Twine.swift
//
//
//
// Created by Thibaut Schmitt on 10/01/2022.
//
import ToolCore
import Foundation
import ArgumentParser
import Foundation
import ToolCore
struct Twine: ParsableCommand {
// MARK: - Command Configuration
static var configuration = CommandConfiguration(
abstract: "Generate strings with twine.",
version: ResgenSwiftVersion
)
// MARK: - Static
static let toolName = "Twine"
static let defaultExtensionName = "String"
static let twineExecutable = "\(FileManager.default.homeDirectoryForCurrentUser.relativePath)/scripts/twine/twine"
static let twineExecutable: String = {
#if os(macOS)
"\(FileManager.default.homeDirectoryForCurrentUser.relativePath)/scripts/twine/twine"
#else
fatalError("This command should run on Mac only")
#endif
}()
// MARK: - Command Options
@OptionGroup var options: TwineOptions
// MARK: - Run
mutating func run() {
print("[\(Self.toolName)] Starting strings generation")
// Check requirements
guard checkRequirements() else { return }
print("[\(Self.toolName)] Will generate strings")
// Generate strings files (lproj files)
for lang in options.langs {
Shell.shell([Self.twineExecutable,
"generate-localization-file", options.inputFile,
"--lang", "\(lang)",
"\(options.outputPath)/\(lang).lproj/\(options.inputFilenameWithoutExt).strings",
"--tags=ios,iosonly,iosOnly"])
Shell.shell(
[
Self.twineExecutable,
"generate-localization-file",
options.inputFile,
"--lang",
"\(lang)",
"\(options.outputPath)/\(lang).lproj/\(options.inputFilenameWithoutExt).strings",
"--tags=ios,iosonly,iosOnly"
]
)
}
// Generate extension
Shell.shell([Self.twineExecutable,
"generate-localization-file", options.inputFile,
"--format", "apple-swift",
"--lang", "\(options.defaultLang)",
options.extensionFilePath,
"--tags=ios,iosonly,iosOnly"])
Shell.shell(
[
Self.twineExecutable,
"generate-localization-file",
options.inputFile,
"--format",
"apple-swift",
"--lang",
"\(options.defaultLang)",
options.extensionFilePath,
"--tags=ios,iosonly,iosOnly"
]
)
print("[\(Self.toolName)] Strings generated")
}
// MARK: - Requirements
private func checkRequirements() -> Bool {
let fileManager = FileManager()
// Input file
guard fileManager.fileExists(atPath: options.inputFile) else {
let error = TwineError.fileNotExists(options.inputFile)
print(error.description)
Twine.exit(withError: error)
Self.exit(withError: error)
}
// Langs
guard options.langs.isEmpty == false else {
let error = TwineError.langsListEmpty
print(error.description)
Twine.exit(withError: error)
Self.exit(withError: error)
}
guard options.langs.contains(options.defaultLang) else {
let error = TwineError.defaultLangsNotInLangs
print(error.description)
Twine.exit(withError: error)
Self.exit(withError: error)
}
// Check if needed to regenerate
guard GeneratorChecker.shouldGenerate(force: options.forceGeneration,
inputFilePath: options.inputFile,
extensionFilePath: options.extensionFilePathGenerated) else {
guard GeneratorChecker.shouldGenerate(
force: options.forceGeneration,
inputFilePath: options.inputFile,
extensionFilePath: options.extensionFilePathGenerated
) else {
print("[\(Self.toolName)] Strings are already up to date :) ")
return false
}
return true
}
}

View File

@ -8,18 +8,19 @@
import Foundation
enum TwineError: Error {
case fileNotExists(String)
case langsListEmpty
case defaultLangsNotInLangs
var description: String {
switch self {
case .fileNotExists(let filename):
return "error: [\(Twine.toolName)] File \(filename) does not exists "
case .langsListEmpty:
return "error: [\(Twine.toolName)] Langs list is empty"
case .defaultLangsNotInLangs:
return "error: [\(Twine.toolName)] Langs list does not contains the default lang"
}

View File

@ -5,25 +5,28 @@
// Created by Thibaut Schmitt on 10/01/2022.
//
import Foundation
import ArgumentParser
import Foundation
// swiftlint:disable no_grouping_extension
struct TwineOptions: ParsableArguments {
@Flag(name: [.customShort("f"), .customShort("F")], help: "Should force generation")
var forceGeneration = false
@Argument(help: "Input files where strings ared defined.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var inputFile: String
@Option(help: "Path where to strings file.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var outputPath: String
@Option(name: .customLong("langs"), help: "Langs to generate.")
fileprivate var langsRaw: String
@Option(help: "Default langs.")
var defaultLang: String
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var extensionOutputPath: String
}
@ -31,6 +34,7 @@ struct TwineOptions: ParsableArguments {
// MARK: - Private var getter
extension TwineOptions {
var langs: [String] {
langsRaw
.split(separator: " ")
@ -41,16 +45,17 @@ extension TwineOptions {
// MARK: - Computed var
extension TwineOptions {
var inputFilenameWithoutExt: String {
URL(fileURLWithPath: inputFile)
.deletingPathExtension()
.lastPathComponent
}
var extensionFilePath: String {
"\(extensionOutputPath)/\(inputFilenameWithoutExt).swift"
}
// "R2String+" is hardcoded in Twine formatter
var extensionFilePathGenerated: String {
"\(extensionOutputPath)/R2String+\(inputFilenameWithoutExt).swift"