From 5a3d273acc771c3cecc918ed87d6842bd11d4ed4 Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Fri, 18 Nov 2022 17:20:21 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Passage=20version=20en=201.2=20Ajout=20de?= =?UTF-8?q?=20la=20d=C3=A9finition=20d'une=20architecture=20de=20classe=20?= =?UTF-8?q?pour=20=C3=A9viter=20de=20d=C3=A9finir=20manuellement=20les=20c?= =?UTF-8?q?lasses=20R/R2Image/R2Fonts....=20(optionel)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/ResgenSwift.xcscheme | 14 +++++++ SampleFiles/resgenConfiguration.yml | 26 +++++++++++++ Sources/ResgenSwift/Generate/Generate.swift | 20 +++++----- .../ResgenSwift/Generate/GenerateError.swift | 4 ++ .../Generator/ArchitectureGenerator.swift | 37 ++++++++++++++++++ .../Generate/Model/ConfigurationFile.swift | 38 ++++++++++++++++++- Sources/ToolCore/Version.swift | 2 +- 7 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/ResgenSwift.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/ResgenSwift.xcscheme index 9b1dd24..354d5d2 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/ResgenSwift.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/ResgenSwift.xcscheme @@ -102,6 +102,20 @@ ReferencedContainer = "container:"> + + + + + + + + String { + " static let \(property) = \(classname)()" + } + + func getClass() -> String { + guard children?.isEmpty == false else { + return "class \(classname) {}" + } + + let classDefinition = [ + "class \(classname) {", + children?.map { $0.getProperty() }.joined(separator: "\n"), + "}" + ] + .compactMap { $0 } + .joined(separator: "\n") + + return [classDefinition, "", getSubclass()] + .compactMap { $0 } + .joined(separator: "\n") + } + + func getSubclass() -> String? { + guard let children else { return nil } + return children.compactMap { arch in + arch.getClass() + } + .joined(separator: "\n\n") + } +} struct ColorsConfiguration: Codable, CustomDebugStringConvertible { let inputFile: String @@ -267,4 +304,3 @@ struct TagsConfiguration: Codable, CustomDebugStringConvertible { """ } } - diff --git a/Sources/ToolCore/Version.swift b/Sources/ToolCore/Version.swift index 11adb0e..b850b78 100644 --- a/Sources/ToolCore/Version.swift +++ b/Sources/ToolCore/Version.swift @@ -7,4 +7,4 @@ import Foundation -public let ResgenSwiftVersion = "1.1" +public let ResgenSwiftVersion = "1.2" -- 2.39.5 From fc427733ee2463f7a9aa6c9ae97d3ef97c5e91e0 Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Tue, 22 Nov 2022 17:14:13 +0100 Subject: [PATCH 2/6] Fix error/warning message to be shown in Xcode.IssueNavigator --- Sources/ResgenSwift/Colors/Colors.swift | 8 ++++---- .../ResgenSwift/Colors/ColorsToolError.swift | 16 ++++++++-------- .../Generator/ColorExtensionGenerator.swift | 2 +- .../Colors/Generator/ColorXcassetHelper.swift | 4 ++-- .../ResgenSwift/Colors/Model/ParsedColor.swift | 2 +- .../Colors/Parser/ColorFileParser.swift | 2 +- Sources/ResgenSwift/Fonts/Fonts.swift | 4 ++-- Sources/ResgenSwift/Fonts/FontsToolError.swift | 10 +++++----- .../ResgenSwift/Fonts/FontsToolHelper.swift | 4 ++-- .../Generator/FontToolContentGenerator.swift | 2 +- .../ResgenSwift/Generate/GenerateError.swift | 8 ++++---- .../Generator/ArchitectureGenerator.swift | 4 ++-- .../Parser/ConfigurationFileParser.swift | 4 ++-- .../Extensions/FileManagerExtensions.swift | 8 ++++---- .../Generator/ImageExtensionGenerator.swift | 2 +- .../Images/Generator/XcassetsGenerator.swift | 4 ++-- Sources/ResgenSwift/Images/Images.swift | 6 +++--- Sources/ResgenSwift/Images/ImagesError.swift | 18 +++++++++--------- .../Generator/StringsFileGenerator.swift | 6 +++--- .../Strings/Generator/TagsGenerator.swift | 2 +- .../ResgenSwift/Strings/Model/Definition.swift | 8 ++++---- .../Strings/Parser/TwineFileParser.swift | 2 +- .../Strings/Stringium/Stringium.swift | 6 +++--- .../Strings/Stringium/StringiumError.swift | 12 ++++++------ Sources/ResgenSwift/Strings/Tag/Tags.swift | 2 +- Sources/ResgenSwift/Strings/Twine/Twine.swift | 6 +++--- .../ResgenSwift/Strings/Twine/TwineError.swift | 6 +++--- 27 files changed, 79 insertions(+), 79 deletions(-) diff --git a/Sources/ResgenSwift/Colors/Colors.swift b/Sources/ResgenSwift/Colors/Colors.swift index 0ffc881..9ee1286 100644 --- a/Sources/ResgenSwift/Colors/Colors.swift +++ b/Sources/ResgenSwift/Colors/Colors.swift @@ -77,21 +77,21 @@ struct Colors: ParsableCommand { // Check if input file exists guard fileManager.fileExists(atPath: options.inputFile) else { let error = ColorsToolError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } // Check if xcassets file exists guard fileManager.fileExists(atPath: options.xcassetsPath) else { let error = ColorsToolError.fileNotExists(options.xcassetsPath) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } // Extension for UIKit and SwiftUI should have different name guard options.extensionName != options.extensionNameSwiftUI else { let error = ColorsToolError.extensionNamesCollision(options.extensionName) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } @@ -117,7 +117,7 @@ struct Colors: ParsableCommand { try fileManager.removeItem(atPath: assetsColorPath) } catch { let error = ColorsToolError.deleteExistingColors("\(options.xcassetsPath)/Colors") - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Colors/ColorsToolError.swift b/Sources/ResgenSwift/Colors/ColorsToolError.swift index 0397fa7..e45f15c 100644 --- a/Sources/ResgenSwift/Colors/ColorsToolError.swift +++ b/Sources/ResgenSwift/Colors/ColorsToolError.swift @@ -20,28 +20,28 @@ enum ColorsToolError: Error { var description: String { switch self { case .extensionNamesCollision(let extensionName): - return "error:[\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" + return "error: [\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" case .badFormat(let info): - return "error:[\(Colors.toolName)] Bad line format: \(info). Accepted format are: colorName=\"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\" \"#RGB/#ARGB\"" + return "error: [\(Colors.toolName)] Bad line format: \(info). Accepted format are: colorName=\"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\"; colorName \"#RGB/#ARGB\" \"#RGB/#ARGB\"" case .writeAsset(let info): - return "error:[\(Colors.toolName)] An error occured while writing color in Xcasset: \(info)" + return "error: [\(Colors.toolName)] An error occured while writing color in Xcasset: \(info)" case .createAssetFolder(let assetsFolder): - return "error:[\(Colors.toolName)] An error occured while creating colors folder `\(assetsFolder)`" + return "error: [\(Colors.toolName)] An error occured while creating colors folder `\(assetsFolder)`" case .writeExtension(let filename, let info): - return "error:[\(Colors.toolName)] An error occured while writing extension in \(filename): \(info)" + return "error: [\(Colors.toolName)] An error occured while writing extension in \(filename): \(info)" case .fileNotExists(let filename): - return "error:[\(Colors.toolName)] File \(filename) does not exists" + return "error: [\(Colors.toolName)] File \(filename) does not exists" case .badColorDefinition(let lightColor, let darkColor): - return "error:[\(Colors.toolName)] One of these two colors has invalid synthax: -\(lightColor)- or -\(darkColor)-" + return "error: [\(Colors.toolName)] One of these two colors has invalid synthax: -\(lightColor)- or -\(darkColor)-" case .deleteExistingColors(let assetsFolder): - return "error:[\(Colors.toolName)] An error occured while deleting colors folder `\(assetsFolder)`" + return "error: [\(Colors.toolName)] An error occured while deleting colors folder `\(assetsFolder)`" } } } diff --git a/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift b/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift index fb32aa5..018c540 100644 --- a/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift +++ b/Sources/ResgenSwift/Colors/Generator/ColorExtensionGenerator.swift @@ -32,7 +32,7 @@ struct ColorExtensionGenerator { try extensionContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = ColorsToolError.writeExtension(extensionFilePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Colors/Generator/ColorXcassetHelper.swift b/Sources/ResgenSwift/Colors/Generator/ColorXcassetHelper.swift index aa4c0db..45eee87 100644 --- a/Sources/ResgenSwift/Colors/Generator/ColorXcassetHelper.swift +++ b/Sources/ResgenSwift/Colors/Generator/ColorXcassetHelper.swift @@ -29,7 +29,7 @@ struct ColorXcassetHelper { withIntermediateDirectories: true) } catch { let error = ColorsToolError.createAssetFolder(colorSetPath) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } } @@ -40,7 +40,7 @@ struct ColorXcassetHelper { try color.contentsJSON().write(to: contentsJsonPathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = ColorsToolError.writeAsset(error.localizedDescription) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Colors/Model/ParsedColor.swift b/Sources/ResgenSwift/Colors/Model/ParsedColor.swift index 951f206..98c7a0b 100644 --- a/Sources/ResgenSwift/Colors/Model/ParsedColor.swift +++ b/Sources/ResgenSwift/Colors/Model/ParsedColor.swift @@ -26,7 +26,7 @@ struct ParsedColor { guard allComponents.contains(true) == false else { let error = ColorsToolError.badColorDefinition(light, dark) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } diff --git a/Sources/ResgenSwift/Colors/Parser/ColorFileParser.swift b/Sources/ResgenSwift/Colors/Parser/ColorFileParser.swift index 70393fe..1db14c2 100644 --- a/Sources/ResgenSwift/Colors/Parser/ColorFileParser.swift +++ b/Sources/ResgenSwift/Colors/Parser/ColorFileParser.swift @@ -37,7 +37,7 @@ class ColorFileParser { guard colorContent.count >= 2 else { let error = ColorsToolError.badFormat(colorLine) - print(error.localizedDescription) + print(error.description) Colors.exit(withError: error) } diff --git a/Sources/ResgenSwift/Fonts/Fonts.swift b/Sources/ResgenSwift/Fonts/Fonts.swift index 0cf494d..f6e172f 100644 --- a/Sources/ResgenSwift/Fonts/Fonts.swift +++ b/Sources/ResgenSwift/Fonts/Fonts.swift @@ -74,14 +74,14 @@ struct Fonts: ParsableCommand { // Check input file exists guard fileManager.fileExists(atPath: options.inputFile) else { let error = FontsToolError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) 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) + print(error.description) Fonts.exit(withError: error) } diff --git a/Sources/ResgenSwift/Fonts/FontsToolError.swift b/Sources/ResgenSwift/Fonts/FontsToolError.swift index 30a8a22..fc2a464 100644 --- a/Sources/ResgenSwift/Fonts/FontsToolError.swift +++ b/Sources/ResgenSwift/Fonts/FontsToolError.swift @@ -17,19 +17,19 @@ enum FontsToolError: Error { var localizedDescription: String { switch self { case .extensionNamesCollision(let extensionName): - return "error:[\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" + return "error: [\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" case .fcScan(let path, let code, let output): - return "error:[\(Fonts.toolName)] Error while getting fontName (fc-scan --format %{postscriptname} \(path). fc-scan exit with \(code) and output is: \(output ?? "no output")" + return "error: [\(Fonts.toolName)] Error while getting fontName (fc-scan --format %{postscriptname} \(path). fc-scan exit with \(code) and output is: \(output ?? "no output")" case .inputFolderNotFound(let inputFolder): - return " error:[\(Fonts.toolName)] Input folder not found: \(inputFolder)" + return "error: [\(Fonts.toolName)] Input folder not found: \(inputFolder)" case .fileNotExists(let filename): - return " error:[\(Fonts.toolName)] File \(filename) does not exists" + return "error: [\(Fonts.toolName)] File \(filename) does not exists" case .writeExtension(let filename, let info): - return "error:[\(Fonts.toolName)] An error occured while writing extension in \(filename): \(info)" + return "error: [\(Fonts.toolName)] An error occured while writing extension in \(filename): \(info)" } } } diff --git a/Sources/ResgenSwift/Fonts/FontsToolHelper.swift b/Sources/ResgenSwift/Fonts/FontsToolHelper.swift index 686db9f..02b3b8d 100644 --- a/Sources/ResgenSwift/Fonts/FontsToolHelper.swift +++ b/Sources/ResgenSwift/Fonts/FontsToolHelper.swift @@ -39,7 +39,7 @@ class FontsToolHelper { let fileManager = FileManager() guard fileManager.fileExists(atPath: inputFolder) else { let error = FontsToolError.inputFolderNotFound(inputFolder) - print(error.localizedDescription) + print(error.description) Fonts.exit(withError: error) } @@ -64,7 +64,7 @@ class FontsToolHelper { guard let fontName = task.output, task.terminationStatus == 0 else { let error = FontsToolError.fcScan(path, task.terminationStatus, task.output) - print(error.localizedDescription) + print(error.description) Fonts.exit(withError: error) } diff --git a/Sources/ResgenSwift/Fonts/Generator/FontToolContentGenerator.swift b/Sources/ResgenSwift/Fonts/Generator/FontToolContentGenerator.swift index eff2dea..45c0a03 100644 --- a/Sources/ResgenSwift/Fonts/Generator/FontToolContentGenerator.swift +++ b/Sources/ResgenSwift/Fonts/Generator/FontToolContentGenerator.swift @@ -38,7 +38,7 @@ class FontExtensionGenerator { try extensionContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = FontsToolError.writeExtension(extensionFilePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Fonts.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Generate/GenerateError.swift b/Sources/ResgenSwift/Generate/GenerateError.swift index b989b2d..9f22c91 100644 --- a/Sources/ResgenSwift/Generate/GenerateError.swift +++ b/Sources/ResgenSwift/Generate/GenerateError.swift @@ -16,19 +16,19 @@ enum GenerateError: Error { var localizedDescription: String { switch self { case .fileNotExists(let filename): - return " error:[\(Generate.toolName)] File \(filename) does not exists" + return "error: [\(Generate.toolName)] File \(filename) does not exists" case .invalidConfigurationFile(let filename): - return " error:[\(Generate.toolName)] File \(filename) is not a valid configuration file" + return "error: [\(Generate.toolName)] File \(filename) is not a valid configuration file" case .commandError(let command, let terminationStatus): let readableCommand = command .map { $0 } .joined(separator: " ") - return "error:[\(Generate.toolName)] An error occured while running command '\(readableCommand)'. Command terminate with status code: \(terminationStatus)" + return "error: [\(Generate.toolName)] An error occured while running command '\(readableCommand)'. Command terminate with status code: \(terminationStatus)" case .writeFile(let filename, let info): - return "error:[\(Generate.toolName)] An error occured while writing file in \(filename): \(info)" + return "error: [\(Generate.toolName)] An error occured while writing file in \(filename): \(info)" } } } diff --git a/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift b/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift index 5dae2d8..8ffa77e 100644 --- a/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift +++ b/Sources/ResgenSwift/Generate/Generator/ArchitectureGenerator.swift @@ -20,7 +20,7 @@ struct ArchitectureGenerator { let filename = "\(architecture.classname).swift" guard let filePath = architecture.path else { let error = GenerateError.writeFile(filename, "Path of file is not defined.") - print(error.localizedDescription) + print(error.description) Generate.exit(withError: error) } @@ -30,7 +30,7 @@ struct ArchitectureGenerator { try architectureContent.write(to: architectureFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = GenerateError.writeFile(filename, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Generate.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Generate/Parser/ConfigurationFileParser.swift b/Sources/ResgenSwift/Generate/Parser/ConfigurationFileParser.swift index 39e64bf..0b0c885 100644 --- a/Sources/ResgenSwift/Generate/Parser/ConfigurationFileParser.swift +++ b/Sources/ResgenSwift/Generate/Parser/ConfigurationFileParser.swift @@ -12,13 +12,13 @@ class ConfigurationFileParser { static func parse(_ configurationFile: String) -> ConfigurationFile { guard let data = FileManager().contents(atPath: configurationFile) else { let error = GenerateError.fileNotExists(configurationFile) - print(error.localizedDescription) + print(error.description) Generate.exit(withError: error) } guard let configuration = try? YAMLDecoder().decode(ConfigurationFile.self, from: data) else { let error = GenerateError.invalidConfigurationFile(configurationFile) - print(error.localizedDescription) + print(error.description) Generate.exit(withError: error) } diff --git a/Sources/ResgenSwift/Images/Extensions/FileManagerExtensions.swift b/Sources/ResgenSwift/Images/Extensions/FileManagerExtensions.swift index c9eb83c..c02e798 100644 --- a/Sources/ResgenSwift/Images/Extensions/FileManagerExtensions.swift +++ b/Sources/ResgenSwift/Images/Extensions/FileManagerExtensions.swift @@ -12,7 +12,7 @@ extension FileManager { var files = [String]() guard let enumerator = self.enumerator(at: URL(string: directory)!, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else { let error = ImagesError.unknown("Cannot enumerate file in \(directory)") - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } @@ -24,7 +24,7 @@ extension FileManager { } } catch { let error = ImagesError.getFileAttributed(fileURL.relativePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } } @@ -35,7 +35,7 @@ extension FileManager { var files = [String]() guard let enumerator = self.enumerator(at: URL(string: directory)!, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else { let error = ImagesError.unknown("Cannot enumerate imageset directory in \(directory)") - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } @@ -47,7 +47,7 @@ extension FileManager { } } catch { let error = ImagesError.getFileAttributed(fileURL.relativePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Images/Generator/ImageExtensionGenerator.swift b/Sources/ResgenSwift/Images/Generator/ImageExtensionGenerator.swift index 5edce9f..3982723 100644 --- a/Sources/ResgenSwift/Images/Generator/ImageExtensionGenerator.swift +++ b/Sources/ResgenSwift/Images/Generator/ImageExtensionGenerator.swift @@ -31,7 +31,7 @@ class ImageExtensionGenerator { try extensionContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = ImagesError.writeFile(extensionFilePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Images/Generator/XcassetsGenerator.swift b/Sources/ResgenSwift/Images/Generator/XcassetsGenerator.swift index 6573c92..6d55599 100644 --- a/Sources/ResgenSwift/Images/Generator/XcassetsGenerator.swift +++ b/Sources/ResgenSwift/Images/Generator/XcassetsGenerator.swift @@ -48,7 +48,7 @@ class XcassetsGenerator { } } let error = ImagesError.unknownImageExtension(parsedImage.name) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) }() @@ -77,7 +77,7 @@ class XcassetsGenerator { withIntermediateDirectories: true) } catch { let error = ImagesError.createAssetFolder(imagesetPath) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Images/Images.swift b/Sources/ResgenSwift/Images/Images.swift index e0264aa..a4ecafa 100644 --- a/Sources/ResgenSwift/Images/Images.swift +++ b/Sources/ResgenSwift/Images/Images.swift @@ -82,7 +82,7 @@ struct Images: ParsableCommand { // Input file guard fileManager.fileExists(atPath: options.inputFile) else { let error = ImagesError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } @@ -92,7 +92,7 @@ struct Images: ParsableCommand { // Extension for UIKit and SwiftUI should have different name guard options.extensionName != options.extensionNameSwiftUI else { let error = ImagesError.extensionNamesCollision(options.extensionName) - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } @@ -117,7 +117,7 @@ struct Images: ParsableCommand { } let error = ImagesError.rsvgConvertNotFound - print(error.localizedDescription) + print(error.description) Images.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Images/ImagesError.swift b/Sources/ResgenSwift/Images/ImagesError.swift index 7f879ee..2a65787 100644 --- a/Sources/ResgenSwift/Images/ImagesError.swift +++ b/Sources/ResgenSwift/Images/ImagesError.swift @@ -21,31 +21,31 @@ enum ImagesError: Error { var localizedDescription: String { switch self { case .extensionNamesCollision(let extensionName): - return "error:[\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" + return "error: [\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" case .inputFolderNotFound(let inputFolder): - return " error:[\(Images.toolName)] Input folder not found: \(inputFolder)" + return "error: [\(Images.toolName)] Input folder not found: \(inputFolder)" case .fileNotExists(let filename): - return " error:[\(Images.toolName)] File \(filename) does not exists" + return "error: [\(Images.toolName)] File \(filename) does not exists" case .unknownImageExtension(let filename): - return " error:[\(Images.toolName)] File \(filename) have an unhandled file extension. Cannot generate image." + return "error: [\(Images.toolName)] File \(filename) have an unhandled file extension. Cannot generate image." case .getFileAttributed(let filename, let errorDescription): - return " error:[\(Images.toolName)] Getting file attributes of \(filename) failed with error: \(errorDescription)" + return "error: [\(Images.toolName)] Getting file attributes of \(filename) failed with error: \(errorDescription)" case .rsvgConvertNotFound: - return " error:[\(Images.toolName)] Can't find rsvg-convert (can be installed with 'brew remove imagemagick && brew install imagemagick --with-librsvg')" + return "error: [\(Images.toolName)] Can't find rsvg-convert (can be installed with 'brew remove imagemagick && brew install imagemagick --with-librsvg')" case .writeFile(let subErrorDescription, let filename): - return " error:[\(Images.toolName)] An error occured while writing content to \(filename): \(subErrorDescription)" + return "error: [\(Images.toolName)] An error occured while writing content to \(filename): \(subErrorDescription)" case .createAssetFolder(let folder): - return "error:[\(Colors.toolName)] An error occured while creating folder `\(folder)`" + return "error: [\(Colors.toolName)] An error occured while creating folder `\(folder)`" case .unknown(let errorDescription): - return " error:[\(Images.toolName)] Unknown error: \(errorDescription)" + return "error: [\(Images.toolName)] Unknown error: \(errorDescription)" } } } diff --git a/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift b/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift index 27edcd9..4fbebfb 100644 --- a/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift +++ b/Sources/ResgenSwift/Strings/Generator/StringsFileGenerator.swift @@ -31,7 +31,7 @@ class StringsFileGenerator { try fileContent.write(to: stringsFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = StringiumError.writeFile(error.localizedDescription, stringsFilePath) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } } @@ -75,7 +75,7 @@ class StringsFileGenerator { stringsFileContent += "\"\(definition.name)\" = \"\(translation)\";\n\n" } else if skipDefinition == false { let error = StringiumError.langNotDefined(lang, definition.name, definition.reference != nil) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } } @@ -101,7 +101,7 @@ class StringsFileGenerator { try extensionFileContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = StringiumError.writeFile(extensionFilePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Strings/Generator/TagsGenerator.swift b/Sources/ResgenSwift/Strings/Generator/TagsGenerator.swift index 15dff7f..ee09d73 100644 --- a/Sources/ResgenSwift/Strings/Generator/TagsGenerator.swift +++ b/Sources/ResgenSwift/Strings/Generator/TagsGenerator.swift @@ -24,7 +24,7 @@ class TagsGenerator { try extensionFileContent.write(to: extensionFilePathURL, atomically: false, encoding: .utf8) } catch (let error) { let error = StringiumError.writeFile(extensionFilePath, error.localizedDescription) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } } diff --git a/Sources/ResgenSwift/Strings/Model/Definition.swift b/Sources/ResgenSwift/Strings/Model/Definition.swift index b7dbe44..458201d 100644 --- a/Sources/ResgenSwift/Strings/Model/Definition.swift +++ b/Sources/ResgenSwift/Strings/Model/Definition.swift @@ -109,7 +109,7 @@ class Definition { func getNSLocalizedStringProperty(forLang lang: String) -> String { guard let translation = translations[lang] else { let error = StringiumError.langNotDefined(lang, name, reference != nil) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } @@ -132,7 +132,7 @@ class Definition { func getNSLocalizedStringStaticProperty(forLang lang: String) -> String { guard let translation = translations[lang] else { let error = StringiumError.langNotDefined(lang, name, reference != nil) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } @@ -157,7 +157,7 @@ class Definition { func getProperty(forLang lang: String) -> String { guard let translation = translations[lang] else { let error = StringiumError.langNotDefined(lang, name, reference != nil) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } @@ -173,7 +173,7 @@ class Definition { func getStaticProperty(forLang lang: String) -> String { guard let translation = translations[lang] else { let error = StringiumError.langNotDefined(lang, name, reference != nil) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } diff --git a/Sources/ResgenSwift/Strings/Parser/TwineFileParser.swift b/Sources/ResgenSwift/Strings/Parser/TwineFileParser.swift index 55b4f08..b7f6803 100644 --- a/Sources/ResgenSwift/Strings/Parser/TwineFileParser.swift +++ b/Sources/ResgenSwift/Strings/Parser/TwineFileParser.swift @@ -84,7 +84,7 @@ class TwineFileParser { } } if invalidDefinitionNames.count > 0 { - print(" warning:[\(Stringium.toolName)] Found \(invalidDefinitionNames.count) definition (\(invalidDefinitionNames.joined(separator: ", "))") + print("warning: [\(Stringium.toolName)] Found \(invalidDefinitionNames.count) definition (\(invalidDefinitionNames.joined(separator: ", "))") } return sections diff --git a/Sources/ResgenSwift/Strings/Stringium/Stringium.swift b/Sources/ResgenSwift/Strings/Stringium/Stringium.swift index ca750c8..d497e00 100644 --- a/Sources/ResgenSwift/Strings/Stringium/Stringium.swift +++ b/Sources/ResgenSwift/Strings/Stringium/Stringium.swift @@ -70,20 +70,20 @@ struct Stringium: ParsableCommand { // Input file guard fileManager.fileExists(atPath: options.inputFile) else { let error = StringiumError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } // Langs guard options.langs.isEmpty == false else { let error = StringiumError.langsListEmpty - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } guard options.langs.contains(options.defaultLang) else { let error = StringiumError.defaultLangsNotInLangs - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } diff --git a/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift b/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift index 852d7ec..844005d 100644 --- a/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift +++ b/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift @@ -17,22 +17,22 @@ enum StringiumError: Error { var localizedDescription: String { switch self { case .fileNotExists(let filename): - return " error:[\(Stringium.toolName)] File \(filename) does not exists " + return "error: [\(Stringium.toolName)] File \(filename) does not exists " case .langsListEmpty: - return " error:[\(Stringium.toolName)] Langs list is empty" + return "error: [\(Stringium.toolName)] Langs list is empty" case .defaultLangsNotInLangs: - return " error:[\(Stringium.toolName)] Langs list does not contains the default lang" + return "error: [\(Stringium.toolName)] Langs list does not contains the default lang" case .writeFile(let subErrorDescription, let filename): - return " error:[\(Stringium.toolName)] An error occured while writing content to \(filename): \(subErrorDescription)" + return "error: [\(Stringium.toolName)] An error occured while writing content to \(filename): \(subErrorDescription)" case .langNotDefined(let lang, let definitionName, let isReference): if isReference { - return " error:[\(Stringium.toolName)] Reference are handled only by TwineTool. Please use it or remove reference from you strings file." + return "error: [\(Stringium.toolName)] Reference are handled only by Twine. Please use it or remove reference from you strings file." } - return " error:[\(Stringium.toolName)] Lang \"\(lang)\" not found for \"\(definitionName)\"" + return "error: [\(Stringium.toolName)] Lang \"\(lang)\" not found for \"\(definitionName)\"" } } } diff --git a/Sources/ResgenSwift/Strings/Tag/Tags.swift b/Sources/ResgenSwift/Strings/Tag/Tags.swift index 5e53208..7fedafa 100644 --- a/Sources/ResgenSwift/Strings/Tag/Tags.swift +++ b/Sources/ResgenSwift/Strings/Tag/Tags.swift @@ -62,7 +62,7 @@ struct Tags: ParsableCommand { // Input file guard fileManager.fileExists(atPath: options.inputFile) else { let error = StringiumError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) Stringium.exit(withError: error) } diff --git a/Sources/ResgenSwift/Strings/Twine/Twine.swift b/Sources/ResgenSwift/Strings/Twine/Twine.swift index 2a48bac..7af478d 100644 --- a/Sources/ResgenSwift/Strings/Twine/Twine.swift +++ b/Sources/ResgenSwift/Strings/Twine/Twine.swift @@ -66,20 +66,20 @@ struct Twine: ParsableCommand { // Input file guard fileManager.fileExists(atPath: options.inputFile) else { let error = TwineError.fileNotExists(options.inputFile) - print(error.localizedDescription) + print(error.description) Twine.exit(withError: error) } // Langs guard options.langs.isEmpty == false else { let error = TwineError.langsListEmpty - print(error.localizedDescription) + print(error.description) Twine.exit(withError: error) } guard options.langs.contains(options.defaultLang) else { let error = TwineError.defaultLangsNotInLangs - print(error.localizedDescription) + print(error.description) Twine.exit(withError: error) } diff --git a/Sources/ResgenSwift/Strings/Twine/TwineError.swift b/Sources/ResgenSwift/Strings/Twine/TwineError.swift index 291f371..ddf0f0f 100644 --- a/Sources/ResgenSwift/Strings/Twine/TwineError.swift +++ b/Sources/ResgenSwift/Strings/Twine/TwineError.swift @@ -15,13 +15,13 @@ enum TwineError: Error { var localizedDescription: String { switch self { case .fileNotExists(let filename): - return " error:[\(Twine.toolName)] File \(filename) does not exists " + return "error: [\(Twine.toolName)] File \(filename) does not exists " case .langsListEmpty: - return " error:[\(Twine.toolName)] Langs list is empty" + return "error: [\(Twine.toolName)] Langs list is empty" case .defaultLangsNotInLangs: - return " error:[\(Twine.toolName)] Langs list does not contains the default lang" + return "error: [\(Twine.toolName)] Langs list does not contains the default lang" } } } -- 2.39.5 From 9ab7e74991cea840b53fb56adabaecb285baf23d Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Tue, 22 Nov 2022 17:37:24 +0100 Subject: [PATCH 3/6] Renaming errors property: localizedDescription -> description Re enabling generation of ressources on commond Architecture will now generate property of subobject as non-static. It will allow usage like R.sub_object.sub_property.property --- Sources/ResgenSwift/Fonts/FontsToolError.swift | 2 +- Sources/ResgenSwift/Generate/Generate.swift | 16 ++++++++-------- Sources/ResgenSwift/Generate/GenerateError.swift | 2 +- .../Generate/Model/ConfigurationFile.swift | 10 +++++----- Sources/ResgenSwift/Images/ImagesError.swift | 2 +- .../Strings/Stringium/StringiumError.swift | 2 +- .../ResgenSwift/Strings/Twine/TwineError.swift | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/ResgenSwift/Fonts/FontsToolError.swift b/Sources/ResgenSwift/Fonts/FontsToolError.swift index fc2a464..d553cd3 100644 --- a/Sources/ResgenSwift/Fonts/FontsToolError.swift +++ b/Sources/ResgenSwift/Fonts/FontsToolError.swift @@ -14,7 +14,7 @@ enum FontsToolError: Error { case fileNotExists(String) case writeExtension(String, String) - var localizedDescription: String { + var description: String { switch self { case .extensionNamesCollision(let extensionName): return "error: [\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" diff --git a/Sources/ResgenSwift/Generate/Generate.swift b/Sources/ResgenSwift/Generate/Generate.swift index 29931b6..8902545 100644 --- a/Sources/ResgenSwift/Generate/Generate.swift +++ b/Sources/ResgenSwift/Generate/Generate.swift @@ -45,14 +45,14 @@ struct Generate: ParsableCommand { ArchitectureGenerator.writeArchitecture(architecture) } -// // Execute commands -// configuration.runnableConfigurations -// .forEach { -// let begin = Date() -// $0.run(projectDirectory: options.projectDirectory, -// force: options.forceGeneration) -// print("Took: \(Date().timeIntervalSince(begin))s\n") -// } + // Execute commands + configuration.runnableConfigurations + .forEach { + let begin = Date() + $0.run(projectDirectory: options.projectDirectory, + force: options.forceGeneration) + print("Took: \(Date().timeIntervalSince(begin))s\n") + } print("[\(Self.toolName)] Resgen ended") } diff --git a/Sources/ResgenSwift/Generate/GenerateError.swift b/Sources/ResgenSwift/Generate/GenerateError.swift index 9f22c91..2ebc045 100644 --- a/Sources/ResgenSwift/Generate/GenerateError.swift +++ b/Sources/ResgenSwift/Generate/GenerateError.swift @@ -13,7 +13,7 @@ enum GenerateError: Error { case commandError([String], String) case writeFile(String, String) - var localizedDescription: String { + var description: String { switch self { case .fileNotExists(let filename): return "error: [\(Generate.toolName)] File \(filename) does not exists" diff --git a/Sources/ResgenSwift/Generate/Model/ConfigurationFile.swift b/Sources/ResgenSwift/Generate/Model/ConfigurationFile.swift index d962db3..9cf8c47 100644 --- a/Sources/ResgenSwift/Generate/Model/ConfigurationFile.swift +++ b/Sources/ResgenSwift/Generate/Model/ConfigurationFile.swift @@ -45,18 +45,18 @@ struct ConfigurationArchitecture: Codable { let path: String? let children: [ConfigurationArchitecture]? - func getProperty() -> String { - " static let \(property) = \(classname)()" + func getProperty(isStatic: Bool) -> String { + " \(isStatic ? "static " : "")let \(property) = \(classname)()" } - func getClass() -> String { + func getClass(generateStaticProperty: Bool = true) -> String { guard children?.isEmpty == false else { return "class \(classname) {}" } let classDefinition = [ "class \(classname) {", - children?.map { $0.getProperty() }.joined(separator: "\n"), + children?.map { $0.getProperty(isStatic: generateStaticProperty) }.joined(separator: "\n"), "}" ] .compactMap { $0 } @@ -70,7 +70,7 @@ struct ConfigurationArchitecture: Codable { func getSubclass() -> String? { guard let children else { return nil } return children.compactMap { arch in - arch.getClass() + arch.getClass(generateStaticProperty: false) } .joined(separator: "\n\n") } diff --git a/Sources/ResgenSwift/Images/ImagesError.swift b/Sources/ResgenSwift/Images/ImagesError.swift index 2a65787..8dcbc57 100644 --- a/Sources/ResgenSwift/Images/ImagesError.swift +++ b/Sources/ResgenSwift/Images/ImagesError.swift @@ -18,7 +18,7 @@ enum ImagesError: Error { case createAssetFolder(String) case unknown(String) - var localizedDescription: String { + var description: String { switch self { case .extensionNamesCollision(let extensionName): return "error: [\(Fonts.toolName)] Error on extension names, extension name and SwiftUI extension name should be different (\(extensionName) is used on both)" diff --git a/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift b/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift index 844005d..ba12a82 100644 --- a/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift +++ b/Sources/ResgenSwift/Strings/Stringium/StringiumError.swift @@ -14,7 +14,7 @@ enum StringiumError: Error { case writeFile(String, String) case langNotDefined(String, String, Bool) - var localizedDescription: String { + var description: String { switch self { case .fileNotExists(let filename): return "error: [\(Stringium.toolName)] File \(filename) does not exists " diff --git a/Sources/ResgenSwift/Strings/Twine/TwineError.swift b/Sources/ResgenSwift/Strings/Twine/TwineError.swift index ddf0f0f..82ed17f 100644 --- a/Sources/ResgenSwift/Strings/Twine/TwineError.swift +++ b/Sources/ResgenSwift/Strings/Twine/TwineError.swift @@ -12,7 +12,7 @@ enum TwineError: Error { case langsListEmpty case defaultLangsNotInLangs - var localizedDescription: String { + var description: String { switch self { case .fileNotExists(let filename): return "error: [\(Twine.toolName)] File \(filename) does not exists " -- 2.39.5 From b662fc64f34cca8478ad8b7029d8db8127945788 Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Tue, 22 Nov 2022 17:54:20 +0100 Subject: [PATCH 4/6] Update Readme Populate CHANGELOG.md based on previous versions --- CHANGELOG.md | 26 ++++++++++++++++++++++ README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..2b2bb02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# v1.1 - SwiftUI compatibility + +## New +- Update plist `UIAppFonts` when generated fonts (use plistBuddy) + - New parameter: `infoPlistPaths` +- Generate SwiftUI extensions for colors, fonts and images + - New parameter: `extensionNameSwiftUI` +- Adding Makefile to install, unsintall and create man page. + +--- +## Fixes +Fix SwiftLint rule `trailing_newline` + + +# v1.0 - Configuration file + +## Major +- A new command has been added: `generate`. Instead of runnning every single command, it will run all necessary command based on a `yaml` configuration file. Check out Readme to know more + +## Minors +- Code refactoring +- Huge performance improvements +- Readme.md update +- Add option to generate static properties/methods (`staticMembers`) +- Add option to specify the project directory (`--project-directory`). It allows to run ResgenSwift from anywhere +- Add `install.sh` script to install ResgenSwift in `/usr/local/bin` diff --git a/README.md b/README.md index 30f4434..eaf249e 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,67 @@ tags: [] ... ``` +### File architecture + +ResgenSwift generate extension of classes. Those classes must exists in your project. You can create them yourself OR you can let ResgenSwift create them by specifying what you want. Do as follow: + +``` +architecture: +  property: R *(required but not used)* +  classname: R +  path: ./path/to/generate +  children: +    - property: images +      classname: R2Image +    - property: strings +      classname: R2String +    - property: fonts +      classname: R2Font +    - property: images +      classname: R2Image +    - property: uikit +      classname: R2UI +      children: +        - property: images +          classname: R2UIImage +        - property: fonts +          classname: R2UIFont +        - property: images +          classname: R2UIImage +``` + +This will generate a file named as the architecture classname: `R.swift`. Based on the previous architecture, it will generate: +``` +class R { + static let images = R2Image() + static let strings = R2String() + static let fonts = R2Font() + static let images = R2Image() + static let uikit = R2UI() +} + +class R2Image {} + +class R2String {} + +class R2Font {} + +class R2Image {} + +class R2UI { + let images = R2UIImage() + let fonts = R2UIFont() + let images = R2UIImage() +} + +class R2UIImage {} + +class R2UIFont {} + +class R2UIImage {} +``` + + ### Usage ```sh -- 2.39.5 From c31d0b16182870adb9cc3a56fa4a6cebe19d627d Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Tue, 22 Nov 2022 17:55:32 +0100 Subject: [PATCH 5/6] Fix typo in CHANGELOG --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2bb02..301fd83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,10 @@ - New parameter: `extensionNameSwiftUI` - Adding Makefile to install, unsintall and create man page. ---- ## Fixes Fix SwiftLint rule `trailing_newline` - +--- # v1.0 - Configuration file ## Major -- 2.39.5 From 188178fe6afb9618686a6ff1392f3d8acf45b030 Mon Sep 17 00:00:00 2001 From: Thibaut Schmitt Date: Thu, 24 Nov 2022 09:13:30 +0100 Subject: [PATCH 6/6] Update Changelog with v1.2 --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 301fd83..27b823b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v1.2 - Architecture generation + +## New +- New section in configuration file: `architecture`. Define your ressources accessors achitecture and let ResgenSwift generate it for you. Check out Readme to know more. + +## Fixes +- Errors and Warnings are now shown in Xcode Issue Navigator + +--- # v1.1 - SwiftUI compatibility ## New @@ -14,7 +23,7 @@ Fix SwiftLint rule `trailing_newline` # v1.0 - Configuration file ## Major -- A new command has been added: `generate`. Instead of runnning every single command, it will run all necessary command based on a `yaml` configuration file. Check out Readme to know more +- A new command has been added: `generate`. Instead of runnning every single command, it will run all necessary command based on a `yaml` configuration file. Check out Readme to know more. ## Minors - Code refactoring -- 2.39.5