// // GeneratorChecker.swift // // // Created by Thibaut Schmitt on 22/12/2021. // import Foundation public class GeneratorChecker { /// Return `true` if inputFile is newer than extensionFile, otherwise `false` public static func shouldGenerate(force: Bool, inputFilePath: String, extensionFilePath: String) -> Bool { guard force == false else { return true } // If inputFile is newer that generated extension -> Regenerate let extensionFileURL = URL(fileURLWithPath: extensionFilePath) let inputFileURL = URL(fileURLWithPath: inputFilePath) let extensionRessourceValues = try? extensionFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey]) let inputFileRessourceValues = try? inputFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey]) if let extensionModificationDate = extensionRessourceValues?.contentModificationDate, let inputFileModificationDate = inputFileRessourceValues?.contentModificationDate { if inputFileModificationDate >= extensionModificationDate { print("Input file is newer that generated extension.") return true } else { return false } } // ModificationDate not available for both file print("⚠️ Could not compare file modication date. ⚠️") return true } }