Add command to generate Colors
This commit is contained in:
@ -29,3 +29,35 @@ public class Shell {
|
||||
return (terminationStatus: task.terminationStatus, output: output)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
64
Sources/CLIToolCore/Extensions.swift
Normal file
64
Sources/CLIToolCore/Extensions.swift
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// Extensions.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 13/12/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// MARK: - String
|
||||
|
||||
public extension String {
|
||||
func removeCharacters(from forbiddenChars: CharacterSet) -> String {
|
||||
let passed = self.unicodeScalars.filter { !forbiddenChars.contains($0) }
|
||||
return String(String.UnicodeScalarView(passed))
|
||||
}
|
||||
|
||||
func removeCharacters(from: String) -> String {
|
||||
return removeCharacters(from: CharacterSet(charactersIn: from))
|
||||
}
|
||||
|
||||
func removeTrailingWhitespace() -> String {
|
||||
var newString = self
|
||||
|
||||
while newString.last?.isWhitespace == true {
|
||||
newString = String(newString.dropLast())
|
||||
}
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func colorComponent() -> (alpha: String, red: String, green: String, blue: String) {
|
||||
var alpha: String = "FF"
|
||||
var red: String
|
||||
var green: String
|
||||
var blue: String
|
||||
|
||||
var colorClean = self
|
||||
.replacingOccurrences(of: "#", with: "")
|
||||
.replacingOccurrences(of: "0x", with: "")
|
||||
|
||||
if colorClean.count == 8 {
|
||||
alpha = String(colorClean.prefix(2))
|
||||
colorClean = String(colorClean.dropFirst(2))
|
||||
}
|
||||
|
||||
red = String(colorClean.prefix(2))
|
||||
colorClean = String(colorClean.dropFirst(2))
|
||||
green = String(colorClean.prefix(2))
|
||||
colorClean = String(colorClean.dropFirst(2))
|
||||
blue = String(colorClean.prefix(2))
|
||||
return (alpha: alpha, red: red, green: green, blue: blue)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Sequence
|
||||
|
||||
extension Sequence where Iterator.Element: Hashable {
|
||||
public func unique() -> [Iterator.Element] {
|
||||
var seen: [Iterator.Element: Bool] = [:]
|
||||
return self.filter { seen.updateValue(true, forKey: $0) == nil }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user