43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//
|
|
// ColorXcassetHelper.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 20/12/2021.
|
|
//
|
|
|
|
import Foundation
|
|
import CLIToolCore
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|