Bugs fixes, Lint fixes, Refactoring
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit

This commit is contained in:
2022-08-29 13:38:46 +02:00
parent e3f90e0d48
commit a54a264447
35 changed files with 652 additions and 401 deletions

View File

@ -137,7 +137,7 @@ class StringsFileGenerator {
private static func getHeader(stringsFilename: String, extensionClassname: String) -> String {
"""
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
// Generated by ResgenSwift.Strings.\(Stringium.toolName) \(ResgenSwiftVersion)
import UIKit

View File

@ -10,37 +10,49 @@ import ToolCore
import ArgumentParser
struct Stringium: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Generate strings with custom scripts.")
// MARK: - Command Configuration
static var configuration = CommandConfiguration(
abstract: "Generate strings with custom scripts.",
version: "0.1.0"
)
// MARK: - Static
static let toolName = "Stringium"
static let defaultExtensionName = "String"
static let noTranslationTag: String = "notranslation"
var extensionFileName: String { "\(options.extensionName)+\(options.extensionSuffix).swift" }
// MARK: - Properties
var extensionFileName: String {
if options.extensionSuffix.isEmpty == false {
return "\(options.extensionName)+\(options.extensionSuffix).swift"
}
return "\(options.extensionName).swift"
}
var extensionFilePath: String { "\(options.extensionOutputPath)/\(extensionFileName)" }
var langs: [String] {
options.langsRaw
.split(separator: " ")
.map { String($0) }
}
var inputFilenameWithoutExt: String {
URL(fileURLWithPath: options.inputFile)
.deletingPathExtension()
.lastPathComponent
}
var stringsFileOutputPath: String {
var outputPath = options.outputPathRaw
if outputPath.last == "/" {
outputPath = String(outputPath.dropLast())
}
return outputPath
var generateStaticVariable: Bool {
options.extensionName == Self.defaultExtensionName
}
// MARK: - Command options
// The `@OptionGroup` attribute includes the flags, options, and
// arguments defined by another `ParsableArguments` type.
@OptionGroup var options: StringiumOptions
// MARK: - Run
mutating func run() {
print("[\(Self.toolName)] Starting strings generation")
@ -54,17 +66,17 @@ struct Stringium: ParsableCommand {
// Generate strings files
StringsFileGenerator.writeStringsFiles(sections: sections,
langs: langs,
langs: options.langs,
defaultLang: options.defaultLang,
tags: ["ios", "iosonly", Self.noTranslationTag],
outputPath: stringsFileOutputPath,
tags: options.tags,
outputPath: options.stringsFileOutputPath,
inputFilenameWithoutExt: inputFilenameWithoutExt)
// Generate extension
StringsFileGenerator.writeExtensionFiles(sections: sections,
defaultLang: options.defaultLang,
tags: ["ios", "iosonly", Self.noTranslationTag],
staticVar: options.extensionName == Self.defaultExtensionName,
tags: options.tags,
staticVar: generateStaticVariable,
inputFilename: inputFilenameWithoutExt,
extensionName: options.extensionName,
extensionFilePath: extensionFilePath)
@ -85,13 +97,13 @@ struct Stringium: ParsableCommand {
}
// Langs
guard langs.isEmpty == false else {
guard options.langs.isEmpty == false else {
let error = StringiumError.langsListEmpty
print(error.localizedDescription)
Stringium.exit(withError: error)
}
guard langs.contains(options.defaultLang) else {
guard options.langs.contains(options.defaultLang) else {
let error = StringiumError.defaultLangsNotInLangs
print(error.localizedDescription)
Stringium.exit(withError: error)

View File

@ -16,20 +16,45 @@ struct StringiumOptions: ParsableArguments {
var inputFile: String
@Option(name: .customLong("output-path"), help: "Path where to strings file.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var outputPathRaw: String
fileprivate var outputPathRaw: String
@Option(name: .customLong("langs"), help: "Langs to generate.")
var langsRaw: String
fileprivate var langsRaw: String
@Option(help: "Default langs.")
var defaultLang: String
@Option(name: .customLong("tags"), help: "Tags to generate.")
fileprivate var tagsRaw: String = "ios iosonly iosOnly notranslation"
@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 String extension. Using default extension name will generate static property.")
var extensionName: String = Stringium.defaultExtensionName
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+String{extensionSuffix}.swift")
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+{extensionSuffix}.swift")
var extensionSuffix: String = ""
}
extension StringiumOptions {
var stringsFileOutputPath: String {
var outputPath = outputPathRaw
if outputPath.last == "/" {
outputPath = String(outputPath.dropLast())
}
return outputPath
}
var langs: [String] {
langsRaw
.split(separator: " ")
.map { String($0) }
}
var tags: [String] {
tagsRaw
.split(separator: " ")
.map { String($0) }
}
}

View File

@ -10,19 +10,42 @@ import ToolCore
import ArgumentParser
struct Tags: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Generate tags extension file.")
// MARK: - Command Configuration
static var configuration = CommandConfiguration(
abstract: "Generate tags extension file.",
version: "0.1.0"
)
// MARK: - Static
static let toolName = "Tags"
static let defaultExtensionName = "Tags"
static let noTranslationTag: String = "notranslation"
var extensionFileName: String { "\(options.extensionName)+\(options.extensionSuffix).swift" }
// MARK: - Properties
var extensionFileName: String {
if options.extensionSuffix.isEmpty == false {
return "\(options.extensionName)+\(options.extensionSuffix).swift"
}
return "\(options.extensionName).swift"
}
var extensionFilePath: String { "\(options.extensionOutputPath)/\(extensionFileName)" }
var generateStaticVariable: Bool {
options.extensionName == Self.defaultExtensionName
}
// MARK: - Command Options
// The `@OptionGroup` attribute includes the flags, options, and
// arguments defined by another `ParsableArguments` type.
@OptionGroup var options: TagsOptions
// MARK: - Run
mutating func run() {
print("[\(Self.toolName)] Starting tagss generation")
@ -38,7 +61,7 @@ struct Tags: ParsableCommand {
TagsGenerator.writeExtensionFiles(sections: sections,
lang: options.lang,
tags: ["ios", "iosonly", Self.noTranslationTag],
staticVar: options.extensionName == Self.defaultExtensionName,
staticVar: generateStaticVariable,
extensionName: options.extensionName,
extensionFilePath: extensionFilePath)

View File

@ -10,22 +10,35 @@ import ToolCore
import ArgumentParser
struct Twine: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Generate strings with twine.")
// MARK: - Command Configuration
static var configuration = CommandConfiguration(
abstract: "Generate strings with twine.",
version: "0.1.0"
)
// MARK: - Static
static let toolName = "Twine"
static let defaultExtensionName = "String"
static let twineExecutable = "\(FileManager.default.homeDirectoryForCurrentUser.relativePath)/scripts/twine/twine"
var langs: [String] { options.langsRaw.split(separator: " ").map { String($0) } }
// MARK: - Properties
var inputFilenameWithoutExt: String { URL(fileURLWithPath: options.inputFile)
.deletingPathExtension()
.lastPathComponent
}
// MARK: - Command Options
// The `@OptionGroup` attribute includes the flags, options, and
// arguments defined by another `ParsableArguments` type.
@OptionGroup var options: TwineOptions
// MARK: - Run
mutating func run() {
print("[\(Self.toolName)] Starting strings generation")
@ -35,7 +48,7 @@ struct Twine: ParsableCommand {
print("[\(Self.toolName)] Will generate strings")
// Generate strings files (lproj files)
for lang in langs {
for lang in options.langs {
Shell.shell(Self.twineExecutable,
"generate-localization-file", options.inputFile,
"--lang", "\(lang)",
@ -68,13 +81,13 @@ struct Twine: ParsableCommand {
}
// Langs
guard langs.isEmpty == false else {
guard options.langs.isEmpty == false else {
let error = TwineError.langsListEmpty
print(error.localizedDescription)
Twine.exit(withError: error)
}
guard langs.contains(options.defaultLang) else {
guard options.langs.contains(options.defaultLang) else {
let error = TwineError.defaultLangsNotInLangs
print(error.localizedDescription)
Twine.exit(withError: error)

View File

@ -19,7 +19,7 @@ struct TwineOptions: ParsableArguments {
var outputPath: String
@Option(name: .customLong("langs"), help: "Langs to generate.")
var langsRaw: String
fileprivate var langsRaw: String
@Option(help: "Default langs.")
var defaultLang: String
@ -27,3 +27,11 @@ struct TwineOptions: ParsableArguments {
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var extensionOutputPath: String
}
extension TwineOptions {
var langs: [String] {
langsRaw
.split(separator: " ")
.map { String($0) }
}
}