From 1e073af5dfe7854d967c04da51bf5912db70ca66 Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Fri, 12 May 2023 11:33:36 +0200 Subject: [PATCH] Fix architecture generation and add enum key of each string in R2String --- Jenkinsfile | 2 +- .../Generated/ColorYolo+GenAllScript.swift | 4 ++-- .../Generated/UIColorYolo+GenAllScript.swift | 4 ++-- .../Generated/FontYolo+GenAllScript.swift | 4 ++-- .../Generated/UIFontYolo+GenAllScript.swift | 4 ++-- .../Generated/ImageYolo+GenAllScript.swift | 4 ++-- .../Generated/UIImage+GenAllScript.swift | 4 ++-- .../Generated/String+GenAllScript.swift | 13 ++++++++-- .../en-us.lproj/sampleStrings.strings | 2 +- .../Generated/en.lproj/sampleStrings.strings | 2 +- .../Generated/fr.lproj/sampleStrings.strings | 2 +- .../Tags/Generated/Tags+GenAllScript.swift | 4 ++-- Sources/ResgenSwift/Generate/Generate.swift | 3 ++- .../Generator/ArchitectureGenerator.swift | 4 ++-- .../Generator/StringsFileGenerator.swift | 24 +++++++++++++++++++ 15 files changed, 57 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8409a21..b2f2f51 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,6 @@ library "openiumpipeline" -env.DEVELOPER_DIR="/Applications/Xcode_13.3.0.app/Contents/Developer" +env.DEVELOPER_DIR= "/Applications/Xcode-14.3.0.app/Contents/Developer" //env.SIMULATOR_DEVICE_TYPES="iPad--7th-generation-" env.IS_PACKAGE_SWIFT=1 env.TARGETS_MACOS=1 diff --git a/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift b/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift index adf6ece..6856326 100644 --- a/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift +++ b/SampleFiles/Colors/Generated/ColorYolo+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Color 1.0 +// Generated by ResgenSwift.Color 1.2 import SwiftUI @@ -18,4 +18,4 @@ extension ColorYolo { var blue_light_dark: Color { Color("blue_light_dark") } -} \ No newline at end of file +} diff --git a/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift b/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift index 5fedca1..d2c7564 100644 --- a/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift +++ b/SampleFiles/Colors/Generated/UIColorYolo+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Color 1.0 +// Generated by ResgenSwift.Color 1.2 import UIKit @@ -18,4 +18,4 @@ extension UIColorYolo { @objc var blue_light_dark: UIColor { UIColor(named: "blue_light_dark")! } -} \ No newline at end of file +} diff --git a/SampleFiles/Fonts/Generated/FontYolo+GenAllScript.swift b/SampleFiles/Fonts/Generated/FontYolo+GenAllScript.swift index de0aa9c..76efac3 100644 --- a/SampleFiles/Fonts/Generated/FontYolo+GenAllScript.swift +++ b/SampleFiles/Fonts/Generated/FontYolo+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Fonts 1.0 +// Generated by ResgenSwift.Fonts 1.2 import SwiftUI @@ -58,4 +58,4 @@ extension FontYolo { func LatoHairlineItalic(withSize size: CGFloat) -> Font { Font.custom(FontName.LatoHairlineItalic.rawValue, size: size) } -} \ No newline at end of file +} diff --git a/SampleFiles/Fonts/Generated/UIFontYolo+GenAllScript.swift b/SampleFiles/Fonts/Generated/UIFontYolo+GenAllScript.swift index 5ba0759..11d04c0 100644 --- a/SampleFiles/Fonts/Generated/UIFontYolo+GenAllScript.swift +++ b/SampleFiles/Fonts/Generated/UIFontYolo+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Fonts 1.0 +// Generated by ResgenSwift.Fonts 1.2 import UIKit @@ -58,4 +58,4 @@ extension UIFontYolo { func LatoHairlineItalic(withSize size: CGFloat) -> UIFont { UIFont(name: FontName.LatoHairlineItalic.rawValue, size: size)! } -} \ No newline at end of file +} diff --git a/SampleFiles/Images/Generated/ImageYolo+GenAllScript.swift b/SampleFiles/Images/Generated/ImageYolo+GenAllScript.swift index 9961903..602c0c2 100644 --- a/SampleFiles/Images/Generated/ImageYolo+GenAllScript.swift +++ b/SampleFiles/Images/Generated/ImageYolo+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Images 1.0 +// Generated by ResgenSwift.Images 1.2 // Images from sampleImages import SwiftUI @@ -28,4 +28,4 @@ extension ImageYolo { var ic_close_article: Image { Image("ic_close_article") } -} \ No newline at end of file +} diff --git a/SampleFiles/Images/Generated/UIImage+GenAllScript.swift b/SampleFiles/Images/Generated/UIImage+GenAllScript.swift index 20dc6ea..f5d4475 100644 --- a/SampleFiles/Images/Generated/UIImage+GenAllScript.swift +++ b/SampleFiles/Images/Generated/UIImage+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Images 1.0 +// Generated by ResgenSwift.Images 1.2 // Images from sampleImages import UIKit @@ -28,4 +28,4 @@ extension UIImage { var ic_close_article: UIImage { UIImage(named: "ic_close_article")! } -} \ No newline at end of file +} diff --git a/SampleFiles/Strings/Generated/String+GenAllScript.swift b/SampleFiles/Strings/Generated/String+GenAllScript.swift index c5decf4..bdccd44 100644 --- a/SampleFiles/Strings/Generated/String+GenAllScript.swift +++ b/SampleFiles/Strings/Generated/String+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Strings.Stringium 1.0 +// Generated by ResgenSwift.Strings.Stringium 1.2 import UIKit @@ -6,6 +6,15 @@ fileprivate let kStringsFileName = "sampleStrings" extension String { + enum Key: String { + case param_lang = "param_lang" + case generic_back = "generic_back" + case generic_loading_data = "generic_loading_data" + case generic_welcome_firstname_format = "generic_welcome_firstname_format" + case test_equal_symbol = "test_equal_symbol" + case placeholders_test_one = "placeholders_test_one" + } + // MARK: - Webservice /// Translation in en : @@ -61,4 +70,4 @@ extension String { func placeholders_test_one(arg0: String, arg1: String, arg2: Int) -> String { String(format: self.placeholders_test_one, arg0, arg1, arg2) } -} \ No newline at end of file +} diff --git a/SampleFiles/Strings/Generated/en-us.lproj/sampleStrings.strings b/SampleFiles/Strings/Generated/en-us.lproj/sampleStrings.strings index 2f6f597..db0b0c9 100644 --- a/SampleFiles/Strings/Generated/en-us.lproj/sampleStrings.strings +++ b/SampleFiles/Strings/Generated/en-us.lproj/sampleStrings.strings @@ -1,6 +1,6 @@ /** * Apple Strings File - * Generated by ResgenSwift 1.0 + * Generated by ResgenSwift 1.2 * Language: en-us */ diff --git a/SampleFiles/Strings/Generated/en.lproj/sampleStrings.strings b/SampleFiles/Strings/Generated/en.lproj/sampleStrings.strings index f92618a..f0c50ed 100644 --- a/SampleFiles/Strings/Generated/en.lproj/sampleStrings.strings +++ b/SampleFiles/Strings/Generated/en.lproj/sampleStrings.strings @@ -1,6 +1,6 @@ /** * Apple Strings File - * Generated by ResgenSwift 1.0 + * Generated by ResgenSwift 1.2 * Language: en */ diff --git a/SampleFiles/Strings/Generated/fr.lproj/sampleStrings.strings b/SampleFiles/Strings/Generated/fr.lproj/sampleStrings.strings index cfc520a..ad1d796 100644 --- a/SampleFiles/Strings/Generated/fr.lproj/sampleStrings.strings +++ b/SampleFiles/Strings/Generated/fr.lproj/sampleStrings.strings @@ -1,6 +1,6 @@ /** * Apple Strings File - * Generated by ResgenSwift 1.0 + * Generated by ResgenSwift 1.2 * Language: fr */ diff --git a/SampleFiles/Tags/Generated/Tags+GenAllScript.swift b/SampleFiles/Tags/Generated/Tags+GenAllScript.swift index f53f115..45fc4ea 100644 --- a/SampleFiles/Tags/Generated/Tags+GenAllScript.swift +++ b/SampleFiles/Tags/Generated/Tags+GenAllScript.swift @@ -1,4 +1,4 @@ -// Generated by ResgenSwift.Strings.Tags 1.0 +// Generated by ResgenSwift.Strings.Tags 1.2 import UIKit @@ -17,4 +17,4 @@ extension Tags { var screen_two: String { "Ecran deux" } -} \ No newline at end of file +} diff --git a/Sources/ResgenSwift/Generate/Generate.swift b/Sources/ResgenSwift/Generate/Generate.swift index 8902545..4ac6685 100644 --- a/Sources/ResgenSwift/Generate/Generate.swift +++ b/Sources/ResgenSwift/Generate/Generate.swift @@ -42,7 +42,8 @@ struct Generate: ParsableCommand { print() if let architecture = configuration.architecture { - ArchitectureGenerator.writeArchitecture(architecture) + ArchitectureGenerator.writeArchitecture(architecture, + projectDirectory: options.projectDirectory) } // Execute commands diff --git a/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift b/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift index 8ffa77e..ba1413c 100644 --- a/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift +++ b/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift @@ -9,7 +9,7 @@ import ToolCore import Foundation struct ArchitectureGenerator { - static func writeArchitecture(_ architecture: ConfigurationArchitecture) { + static func writeArchitecture(_ architecture: ConfigurationArchitecture, projectDirectory: String) { // Create extension content let architectureContent = [ "// Generated by ResgenSwift.\(Generate.toolName) \(ResgenSwiftVersion)", @@ -18,7 +18,7 @@ struct ArchitectureGenerator { .joined(separator: "\n\n") let filename = "\(architecture.classname).swift" - guard let filePath = architecture.path else { + guard let filePath = architecture.path?.prependIfRelativePath(projectDirectory) else { let error = GenerateError.writeFile(filename, "Path of file is not defined.") print(error.description) Generate.exit(withError: error) diff --git a/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift b/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift index 4fbebfb..e8c20fc 100644 --- a/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift +++ b/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift @@ -111,6 +111,7 @@ class StringsFileGenerator { static func getExtensionContent(sections: [Section], defaultLang lang: String, tags: [String], staticVar: Bool, inputFilename: String, extensionName: String) -> String { [ Self.getHeader(stringsFilename: inputFilename, extensionClassname: extensionName), + Self.getEnumKey(sections: sections, tags: tags), Self.getProperties(sections: sections, defaultLang: lang, tags: tags, staticVar: staticVar), Self.getFooter() ] @@ -131,6 +132,29 @@ class StringsFileGenerator { """ } + private static func getEnumKey(sections: [Section], tags: [String]) -> String { + var enumDefinition = "\n enum Key: String {\n" + + sections.forEach { section in + // Check that at least one string will be generated + guard section.hasOneOrMoreMatchingTags(tags: tags) else { + return // Go to next section + } + + section.definitions.forEach { definition in + guard definition.hasOneOrMoreMatchingTags(inputTags: tags) == true else { + return // Go to next definition + } + debugPrint("Found definition") + enumDefinition += " case \(definition.name) = \"\(definition.name)\"\n" + } + } + + enumDefinition += " }" + + return enumDefinition + } + private static func getProperties(sections: [Section], defaultLang lang: String, tags: [String], staticVar: Bool) -> String { sections.compactMap { section in // Check that at least one string will be generated