2022-12-05 11:43:30 +01:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
func checkDependencies() -> Bool {
|
|
|
|
print("--- DEPENDENCIES -----------------------------------")
|
|
|
|
print(" ")
|
2022-12-05 11:51:19 +01:00
|
|
|
defer { print(" ") }
|
2022-12-05 17:49:15 +01:00
|
|
|
var valid = true
|
|
|
|
valid = checkImageOptimAvailability() && valid
|
|
|
|
valid = checkMagickAvailability() && valid
|
|
|
|
valid = checkCwebpAvailability() && valid
|
|
|
|
valid = checkAvifAvailability() && valid
|
|
|
|
valid = checkUglifyJsAvailability() && valid
|
|
|
|
valid = checkCleanCssAvailability() && valid
|
|
|
|
return valid
|
2022-12-05 11:43:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" ImageOptim: Not found, download app from https://imageoptim.com/mac and install using 'npm install imageoptim-cli'")
|
2022-12-05 11:43:30 +01:00
|
|
|
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 {
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" Magick: Not found, install using 'brew install imagemagick'")
|
2022-12-05 11:43:30 +01:00
|
|
|
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 {
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" cwebp: Not found, download from https://developers.google.com/speed/webp/download")
|
2022-12-05 11:43:30 +01:00
|
|
|
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 {
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" avif: Not found, install using 'npm install avif'")
|
2022-12-05 11:43:30 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
print(" avif: Failed to get version (\(error))")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2022-12-05 17:49:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
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)'")
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" uglify-js: Not found, install using 'npm install uglify-js'")
|
2022-12-05 17:49:15 +01:00
|
|
|
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 {
|
2023-02-01 20:27:11 +01:00
|
|
|
print(" cleancss: Not found, install using 'npm install clean-css-cli'")
|
2022-12-05 17:49:15 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
print(" cleancss: Failed to get version (\(error))")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|