Optional generation of Images extension. Make extensionOutputPath optional for Images and Colors cause it's not needed if no extensionName are provided

This commit is contained in:
2025-07-17 10:23:05 +02:00
parent 4426091dcb
commit e22f9ba894
12 changed files with 132 additions and 97 deletions

View File

@@ -110,6 +110,17 @@ struct Colors: ParsableCommand {
}
}
// If an extension need to be generated, ensure extensionOutputPath is defined
if options.extensionName != nil ||
options.extensionNameUIKit != nil {
guard let extensionOutputPath = options.extensionOutputPath,
extensionOutputPath.isEmpty == false else {
let error = ColorsToolError.missingExtensionPath
print(error.description)
Self.exit(withError: error)
}
}
// Check if needed to regenerate
let fileToCompareToInput: String = {
// If there is no extension file to compare

View File

@@ -17,6 +17,7 @@ enum ColorsToolError: Error {
case fileNotExists(String)
case badColorDefinition(String, String)
case deleteExistingColors(String)
case missingExtensionPath
var description: String {
switch self {
@@ -43,6 +44,9 @@ enum ColorsToolError: Error {
case .deleteExistingColors(let assetsFolder):
return "error: [\(Colors.toolName)] An error occured while deleting colors folder `\(assetsFolder)`"
case .missingExtensionPath:
return "error: [\(Colors.toolName)] Extension need to be generated but no `extensionOutputPath` is provided"
}
}
}

View File

@@ -24,12 +24,12 @@ struct ColorsToolOptions: ParsableArguments {
@Option(help: "Path of xcassets where to generate colors", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var xcassetsPath: String
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var extensionOutputPath: String
@Option(help: "Tell if it will generate static properties or not")
var staticMembers: Bool = false
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
var extensionOutputPath: String?
@Option(help: "Extension name. If not specified, no extension will be generated.")
var extensionName: String?
@@ -56,7 +56,7 @@ extension ColorsToolOptions {
}
var extensionFilePath: String? {
guard let extensionFileName else { return nil }
guard let extensionOutputPath, let extensionFileName else { return nil }
return "\(extensionOutputPath)/\(extensionFileName)"
}
@@ -73,7 +73,7 @@ extension ColorsToolOptions {
}
var extensionFilePathUIKit: String? {
guard let extensionFileNameUIKit else { return nil }
guard let extensionOutputPath, let extensionFileNameUIKit else { return nil }
return "\(extensionOutputPath)/\(extensionFileNameUIKit)"
}