Passage version en 1.2
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit

Ajout de la définition d'une architecture de classe pour éviter de définir manuellement les classes R/R2Image/R2Fonts.... (optionel)
This commit is contained in:
Thibaut Schmitt 2022-11-18 17:20:21 +01:00
parent a7a850799d
commit 5a3d273acc
7 changed files with 130 additions and 11 deletions

View File

@ -102,6 +102,20 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "generate"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "&quot;$(PROJECT_DIR)/../SampleFiles/resgenConfiguration.yml&quot;"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--project-directory &quot;$(PROJECT_DIR)&quot;"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"

View File

@ -1,4 +1,30 @@
---
#
# Class architecture
#
architecture:
property: R
classname: R
path: ./Tags
children:
- property: images
classname: R2Image
- property: strings
classname: R2String
- property: fonts
classname: R2Font
- property: images
classname: R2Image
- property: ui
classname: R2UI
children:
- property: images
classname: R2UIImage
- property: fonts
classname: R2UIFont
- property: images
classname: R2UIImage
#
# Strings
#

View File

@ -41,16 +41,18 @@ struct Generate: ParsableCommand {
print(" - \(configuration.tags.count) tags configuration(s)")
print()
print("Input file: \(configuration.colors.first?.inputFile ?? "no input file")")
if let architecture = configuration.architecture {
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")
}

View File

@ -11,6 +11,7 @@ enum GenerateError: Error {
case fileNotExists(String)
case invalidConfigurationFile(String)
case commandError([String], String)
case writeFile(String, String)
var localizedDescription: String {
switch self {
@ -25,6 +26,9 @@ enum GenerateError: Error {
.map { $0 }
.joined(separator: " ")
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)"
}
}
}

View File

@ -0,0 +1,37 @@
//
// ArchitectureGenerator.swift
//
//
// Created by Thibaut Schmitt on 18/11/2022.
//
import ToolCore
import Foundation
struct ArchitectureGenerator {
static func writeArchitecture(_ architecture: ConfigurationArchitecture) {
// Create extension content
let architectureContent = [
"// Generated by ResgenSwift.\(Generate.toolName) \(ResgenSwiftVersion)",
architecture.getClass()
]
.joined(separator: "\n\n")
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)
Generate.exit(withError: error)
}
// Write content
let architectureFilePathURL = URL(fileURLWithPath: "\(filePath)/\(filename)")
do {
try architectureContent.write(to: architectureFilePathURL, atomically: false, encoding: .utf8)
} catch (let error) {
let error = GenerateError.writeFile(filename, error.localizedDescription)
print(error.localizedDescription)
Generate.exit(withError: error)
}
}
}

View File

@ -8,6 +8,7 @@
import Foundation
struct ConfigurationFile: Codable, CustomDebugStringConvertible {
var architecture: ConfigurationArchitecture?
var colors: [ColorsConfiguration]
var fonts: [FontsConfiguration]
var images: [ImagesConfiguration]
@ -38,6 +39,42 @@ struct ConfigurationFile: Codable, CustomDebugStringConvertible {
}
}
struct ConfigurationArchitecture: Codable {
let property: String
let classname: String
let path: String?
let children: [ConfigurationArchitecture]?
func getProperty() -> 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 {
"""
}
}

View File

@ -7,4 +7,4 @@
import Foundation
public let ResgenSwiftVersion = "1.1"
public let ResgenSwiftVersion = "1.2"