Check more dependencies, fix bug

This commit is contained in:
Christoph Hagen 2022-12-05 17:49:15 +01:00
parent deb7e6187e
commit f185191b7f

View File

@ -4,7 +4,14 @@ func checkDependencies() -> Bool {
print("--- DEPENDENCIES -----------------------------------")
print(" ")
defer { print(" ") }
return checkImageOptimAvailability() && checkMagickAvailability() && checkCwebpAvailability() && checkAvifAvailability()
var valid = true
valid = checkImageOptimAvailability() && valid
valid = checkMagickAvailability() && valid
valid = checkCwebpAvailability() && valid
valid = checkAvifAvailability() && valid
valid = checkUglifyJsAvailability() && valid
valid = checkCleanCssAvailability() && valid
return valid
}
private func checkImageOptimAvailability() -> Bool {
@ -73,3 +80,40 @@ private func checkAvifAvailability() -> Bool {
}
return true
}
private func checkUglifyJsAvailability() -> Bool {
do {
let output = try safeShell("uglifyjs --version")
let version = output.dropBeforeFirst("uglify-js").components(separatedBy: ".").compactMap { Int($0.trimmed) }
if version.count > 1 {
print(" uglify-js: \(version.map { "\($0)" }.joined(separator: "."))")
} else {
print("'\(output)'")
print(" uglify-js: Not found")
return false
}
} catch {
print(" uglify-js: Failed to get version (\(error))")
return false
}
return true
}
private func checkCleanCssAvailability() -> Bool {
do {
let output = try safeShell("cleancss --version")
let version = output.components(separatedBy: ".").compactMap { Int($0.trimmed) }
if version.count > 1 {
print(" cleancss: \(version.map { "\($0)" }.joined(separator: "."))")
} else {
print(" cleancss: Not found")
return false
}
} catch {
print(" cleancss: Failed to get version (\(error))")
return false
}
return true
}