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

@ -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) }
}
}