feat(RES-43): Fix du warning magick convert (#16)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good

Reviewed-on: #16
This commit is contained in:
2025-05-05 10:36:51 +02:00
parent ccda606af5
commit 166026a766
50 changed files with 334 additions and 166 deletions

View File

@ -31,6 +31,7 @@ class XcassetsGenerator {
func generateXcassets(inputPath: String, imagesToGenerate: [ParsedImage], xcassetsPath: String) {
let fileManager = FileManager()
let svgConverter = Images.getSvgConverterPath()
let magickConvert = Images.getMagickConvertPath()
let allSubFiles = fileManager.getAllRegularFileIn(directory: inputPath)
var generatedAssetsPaths = [String]()
@ -148,7 +149,7 @@ class XcassetsGenerator {
// convert path/to/image.png -resize x300 path/to/output.png
Shell.shell(
[
"convert",
"\(magickConvert)",
"\(imageData.path)",
"-resize",
"\(convertArguments.x1.width ?? "")x\(convertArguments.x1.height ?? "")",
@ -157,7 +158,7 @@ class XcassetsGenerator {
)
Shell.shell(
[
"convert",
"\(magickConvert)",
"\(imageData.path)",
"-resize",
"\(convertArguments.x2.width ?? "")x\(convertArguments.x2.height ?? "")",
@ -166,7 +167,7 @@ class XcassetsGenerator {
)
Shell.shell(
[
"convert",
"\(magickConvert)",
"\(imageData.path)",
"-resize",
"\(convertArguments.x3.width ?? "")x\(convertArguments.x3.height ?? "")",

View File

@ -128,4 +128,22 @@ struct Images: ParsableCommand {
print(error.description)
Self.exit(withError: error)
}
@discardableResult
static func getMagickConvertPath() -> String {
// WARNING: The convert command is deprecated in IMv7, use "magick" instead of "convert"
let taskMagick = Shell.shell(["which", "magick"])
if taskMagick.terminationStatus == 0 {
return taskMagick.output!.removeCharacters(from: CharacterSet.whitespacesAndNewlines) // swiftlint:disable:this force_unwrapping
}
let taskConvert = Shell.shell(["which", "convert"])
if taskConvert.terminationStatus == 0 {
return taskMagick.output!.removeCharacters(from: CharacterSet.whitespacesAndNewlines) // swiftlint:disable:this force_unwrapping
}
let error = ImagesError.magickConvertNotFound
print(error.description)
Self.exit(withError: error)
}
}

View File

@ -15,6 +15,7 @@ enum ImagesError: Error {
case unknownImageExtension(String)
case getFileAttributed(String, String)
case rsvgConvertNotFound
case magickConvertNotFound
case writeFile(String, String)
case createAssetFolder(String)
case unknown(String)
@ -39,6 +40,9 @@ enum ImagesError: Error {
case .rsvgConvertNotFound:
return "error: [\(Images.toolName)] Can't find rsvg-convert (can be installed with 'brew remove imagemagick && brew install librsvg')"
case .magickConvertNotFound:
return "error: [\(Images.toolName)] Can't find magick or convert (can be installed with 'brew install imagemagick')"
case let .writeFile(subErrorDescription, filename):
return "error: [\(Images.toolName)] An error occured while writing content to \(filename): \(subErrorDescription)"

View File

@ -51,8 +51,6 @@ enum ImageFileParser {
imagesToGenerate.append(image)
}
print(imagesToGenerate)
return imagesToGenerate.filter {
$0.tags.contains(platform.rawValue)
}