Mise à jour des headers des fichiers générés
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
40
Sources/ToolCore/GeneratorChecker.swift
Normal file
40
Sources/ToolCore/GeneratorChecker.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
15
Sources/ToolCore/SequenceExtensions.swift
Normal file
15
Sources/ToolCore/SequenceExtensions.swift
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// SequenceExtension.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 04/01/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Sequence where Iterator.Element: Hashable {
|
||||
func unique() -> [Iterator.Element] {
|
||||
var seen: [Iterator.Element: Bool] = [:]
|
||||
return self.filter { seen.updateValue(true, forKey: $0) == nil }
|
||||
}
|
||||
}
|
51
Sources/ToolCore/Shell.swift
Normal file
51
Sources/ToolCore/Shell.swift
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// Shell.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 22/12/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class Shell {
|
||||
|
||||
@discardableResult
|
||||
public static func shell(_ args: String...) -> (terminationStatus: Int32, output: String?) {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/env"
|
||||
task.arguments = args
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
|
||||
guard let output: String = String(data: data, encoding: .utf8) else {
|
||||
return (terminationStatus: task.terminationStatus, output: nil)
|
||||
}
|
||||
|
||||
return (terminationStatus: task.terminationStatus, output: output)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
public static func shell(_ args: [String]) -> (terminationStatus: Int32, output: String?) {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/env"
|
||||
task.arguments = args
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
|
||||
guard let output: String = String(data: data, encoding: .utf8) else {
|
||||
return (terminationStatus: task.terminationStatus, output: nil)
|
||||
}
|
||||
|
||||
return (terminationStatus: task.terminationStatus, output: output)
|
||||
}
|
||||
}
|
87
Sources/ToolCore/StringExtensions.swift
Normal file
87
Sources/ToolCore/StringExtensions.swift
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Extensions.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 13/12/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
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 replacingOccurrences(of: [String], with: String) -> Self {
|
||||
var tmp = self
|
||||
for e in of {
|
||||
tmp = tmp.replacingOccurrences(of: e, with: with)
|
||||
}
|
||||
return tmp
|
||||
}
|
||||
|
||||
func removeTrailingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
while newString.last?.isWhitespace == true {
|
||||
newString = String(newString.dropLast())
|
||||
}
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func removeLeadingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
while newString.first?.isWhitespace == true {
|
||||
newString = String(newString.dropFirst())
|
||||
}
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func removeLeadingTrailingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
newString = newString.removeLeadingWhitespace()
|
||||
newString = newString.removeTrailingWhitespace()
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func escapeDoubleQuote() -> Self {
|
||||
replacingOccurrences(of: "\"", with: "\\\"")
|
||||
}
|
||||
|
||||
func replaceTiltWithHomeDirectoryPath() -> Self {
|
||||
replacingOccurrences(of: "~", with: "\(FileManager.default.homeDirectoryForCurrentUser.relativePath)")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
10
Sources/ToolCore/Version.swift
Normal file
10
Sources/ToolCore/Version.swift
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Version.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 25/07/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public let ResgenSwiftVersion = "1.0.0"
|
Reference in New Issue
Block a user