Add checker class to check if generation of font are required + Split CLIToolCore in multiple file (one by class)

This commit is contained in:
2021-12-22 10:28:38 +01:00
parent e8545955f6
commit 780efc8817
12 changed files with 251 additions and 40 deletions

View File

@ -0,0 +1,40 @@
//
// 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
}
}