From f185191b7f0407381ef1fafbd56bc621b0f79a66 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 5 Dec 2022 17:49:15 +0100 Subject: [PATCH] Check more dependencies, fix bug --- .../Processing/DependencyCheck.swift | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/Sources/Generator/Processing/DependencyCheck.swift b/Sources/Generator/Processing/DependencyCheck.swift index 2a2511b..03703d0 100644 --- a/Sources/Generator/Processing/DependencyCheck.swift +++ b/Sources/Generator/Processing/DependencyCheck.swift @@ -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 +}