From 464ece4a03dae04e8ece185086d2a576d6fa098c Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 5 Dec 2022 11:51:19 +0100 Subject: [PATCH] Improve summary print --- .../Generator/Processing/DependencyCheck.swift | 6 ++---- Sources/Generator/run.swift | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/Generator/Processing/DependencyCheck.swift b/Sources/Generator/Processing/DependencyCheck.swift index 350d2de..2a2511b 100644 --- a/Sources/Generator/Processing/DependencyCheck.swift +++ b/Sources/Generator/Processing/DependencyCheck.swift @@ -3,10 +3,8 @@ import Foundation func checkDependencies() -> Bool { print("--- DEPENDENCIES -----------------------------------") print(" ") - let result = checkImageOptimAvailability() && checkMagickAvailability() && checkCwebpAvailability() && checkAvifAvailability() - print(" Complete: \(result ? "Yes" : "No")") - print(" ") - return result + defer { print(" ") } + return checkImageOptimAvailability() && checkMagickAvailability() && checkCwebpAvailability() && checkAvifAvailability() } private func checkImageOptimAvailability() -> Bool { diff --git a/Sources/Generator/run.swift b/Sources/Generator/run.swift index 48d524e..03db8b4 100644 --- a/Sources/Generator/run.swift +++ b/Sources/Generator/run.swift @@ -110,8 +110,8 @@ private func copyFiles(files: FileData, configuration: Configuration, runFolder: generator.generate() } -private func finish(start: Date) { - print("----------------------------------------------------") +private func finish(start: Date, complete: Bool) { + print("--- SUMMARY ----------------------------------------") print(" ") let duration = Int(-start.timeIntervalSinceNow.rounded()) if duration < 60 { @@ -121,11 +121,19 @@ private func finish(start: Date) { } else { print(String(format: " Duration: %d:%02d:%02d", duration / 3600, (duration / 60) % 60, duration % 60)) } - print("") + print(" Complete: \(complete ? "Yes" : "No")") + print(" ") + print("----------------------------------------------------") } private func generate(configPath: String) throws { let start = Date() + var complete = false + + defer { + // 6. Print summary + finish(start: start, complete: complete) + } print(" ") @@ -167,6 +175,5 @@ private func generate(configPath: String) throws { // 5. Copy/minify files copyFiles(files: files, configuration: configuration, runFolder: runFolder) - // 6. Print summary - finish(start: start) + complete = true }