import Foundation func checkDependencies() -> Bool { print("--- DEPENDENCIES -----------------------------------") print(" ") let result = checkImageOptimAvailability() && checkMagickAvailability() && checkCwebpAvailability() && checkAvifAvailability() print(" Complete: \(result ? "Yes" : "No")") print(" ") return result } private func checkImageOptimAvailability() -> Bool { do { let output = try safeShell("imageoptim --version") let version = output.components(separatedBy: ".").compactMap { Int($0.trimmed) } if version.count > 1 { print(" ImageOptim: \(version.map { "\($0)" }.joined(separator: "."))") } else { print(" ImageOptim: Not found") return false } } catch { print(" ImageOptim: Failed to get version (\(error))") return false } return true } private func checkMagickAvailability() -> Bool { do { let output = try safeShell("magick --version") guard let version = output.components(separatedBy: "ImageMagick ").dropFirst().first? .components(separatedBy: " ").first else { print(" Magick: Not found") return false } print(" Magick: \(version)") } catch { print(" Magick: Failed to get version (\(error))") return false } return true } private func checkCwebpAvailability() -> Bool { do { let output = try safeShell("cwebp -version") let version = output.components(separatedBy: ".").compactMap { Int($0.trimmed) } if version.count > 1 { print(" cwebp: \(version.map { "\($0)" }.joined(separator: "."))") } else { print(" cwebp: Not found") return false } } catch { print(" cwebp: Failed to get version (\(error))") return false } return true } private func checkAvifAvailability() -> Bool { do { let output = try safeShell("npx avif --version") let version = output.components(separatedBy: ".").compactMap { Int($0.trimmed) } if version.count > 1 { print(" avif: \(version.map { "\($0)" }.joined(separator: "."))") } else { print(" avif: Not found") return false } } catch { print(" avif: Failed to get version (\(error))") return false } return true }