50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
//
|
|
// GeneratorFontCheck.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 22/12/2021.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class GeneratorFontChecker {
|
|
|
|
/// Will check if first line contains exactly all font filenames and nothinf more
|
|
static func shouldGenerate(force: Bool, inputFilenames: [String], extensionFilePath: String) -> Bool {
|
|
guard force == false else {
|
|
return true
|
|
}
|
|
|
|
let fileManager = FileManager()
|
|
guard fileManager.fileExists(atPath: extensionFilePath) else {
|
|
return true
|
|
}
|
|
|
|
let extensionFileContent = try! String(contentsOfFile: extensionFilePath, encoding: .utf8)
|
|
|
|
guard let extensionComparableLine = extensionFileContent.components(separatedBy: .newlines).first else {
|
|
// First line to compare unavailable -> force generation
|
|
return true
|
|
}
|
|
|
|
let extensionFontNames: [String] = extensionComparableLine
|
|
.split(separator: " ")
|
|
.dropFirst()
|
|
.map { String($0) }
|
|
|
|
// If count is different, some fonts has been added or removed
|
|
if inputFilenames.count != extensionFontNames.count {
|
|
return true
|
|
}
|
|
|
|
// Same number of elements, check if all fonts to generate has been already generated in extension
|
|
for inputFile in inputFilenames {
|
|
if extensionFontNames.contains(inputFile) == false {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
}
|