resgen.swift/Sources/ColorTool/ColorXcassetHelper.swift
Thibaut Schmitt efd04299a8
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Mise à jour des headers des fichiers générés
2022-07-25 09:56:54 +02:00

43 lines
1.2 KiB
Swift

//
// ColorXcassetHelper.swift
//
//
// Created by Thibaut Schmitt on 20/12/2021.
//
import Foundation
import ToolCore
struct ColorXcassetHelper {
let xcassetsPath: String
let colors: [GenColor]
func generateXcassetColors() {
colors.forEach {
generateColorSetAssets(from: $0)
}
}
// Generate ColorSet in XCAssets file
private func generateColorSetAssets(from color: GenColor) {
// Create ColorSet
let colorSetPath = "\(xcassetsPath)/Colors/\(color.name).colorset"
Shell.shell("mkdir", "-p", "\(colorSetPath)")
// Create Contents.json in ColorSet
let contentsJsonPath = "\(colorSetPath)/Contents.json"
Shell.shell("touch", "\(contentsJsonPath)")
// Write content in Contents.json
let contentsJsonPathURL = URL(fileURLWithPath: contentsJsonPath)
do {
try color.contentsJSON().write(to: contentsJsonPathURL, atomically: true, encoding: .utf8)
} catch (let error) {
let error = ColorToolError.writeAsset(error.localizedDescription)
print(error.localizedDescription)
ColorTool.exit(withError: error)
}
}
}