Refactor + Bugs fixes on Strings + Gestion de la génération des images
This commit is contained in:
42
Sources/ColorTool/ColorXcassetHelper.swift
Normal file
42
Sources/ColorTool/ColorXcassetHelper.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user