Configure + run SwiftFormat
This commit is contained in:
parent
7d277a0e43
commit
1f6b55014a
10 changed files with 53 additions and 38 deletions
|
@ -9,7 +9,7 @@ final class AndroidGenerator: Generator {
|
|||
self.context = context
|
||||
}
|
||||
|
||||
func generate(data: [String : ColorDef]) throws -> FileWrapper {
|
||||
func generate(data: [String: ColorDef]) throws -> FileWrapper {
|
||||
var xml = """
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
@ -23,8 +23,8 @@ final class AndroidGenerator: Generator {
|
|||
|
||||
let value: String
|
||||
switch color {
|
||||
case .color(let colorValue): value = colorValue.description
|
||||
case .reference(let ref): value = "@color/\(prefix)\(ref.camelCasePathToSnakeCase())"
|
||||
case let .color(colorValue): value = colorValue.description
|
||||
case let .reference(ref): value = "@color/\(prefix)\(ref.camelCasePathToSnakeCase())"
|
||||
}
|
||||
|
||||
xml += """
|
||||
|
|
|
@ -10,8 +10,8 @@ final class AssetCatalogGenerator: Generator {
|
|||
self.context = context
|
||||
}
|
||||
|
||||
func generate(data: [String : ColorDef]) throws -> FileWrapper {
|
||||
let root = FileWrapper(directoryWithFileWrappers: ["Contents.json" : FileWrapper(catalog)])
|
||||
func generate(data: [String: ColorDef]) throws -> FileWrapper {
|
||||
let root = FileWrapper(directoryWithFileWrappers: ["Contents.json": FileWrapper(catalog)])
|
||||
let colorRoot: FileWrapper
|
||||
|
||||
if let prefix = context.prefix?.insertCamelCaseSeparators() {
|
||||
|
@ -53,7 +53,7 @@ final class AssetCatalogGenerator: Generator {
|
|||
|
||||
private extension Color {
|
||||
func json() -> String {
|
||||
return """
|
||||
"""
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
|
@ -79,12 +79,11 @@ private extension Color {
|
|||
|
||||
func fileWrapper() -> FileWrapper {
|
||||
FileWrapper(directoryWithFileWrappers: [
|
||||
"Contents.json": FileWrapper(json())
|
||||
"Contents.json": FileWrapper(json()),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let group = """
|
||||
{
|
||||
"info" : {
|
||||
|
|
|
@ -8,7 +8,7 @@ final class HTMLGenerator: Generator {
|
|||
self.context = context
|
||||
}
|
||||
|
||||
func generate(data: [String : ColorDef]) throws -> FileWrapper {
|
||||
func generate(data: [String: ColorDef]) throws -> FileWrapper {
|
||||
var html = """
|
||||
<html>
|
||||
<head>
|
||||
|
|
|
@ -11,7 +11,7 @@ private struct GeneratorOption: EnumerableFlag, CustomStringConvertible {
|
|||
static let allCases: [GeneratorOption] = [
|
||||
.init(type: AssetCatalogGenerator.self),
|
||||
.init(type: AndroidGenerator.self),
|
||||
.init(type: HTMLGenerator.self)
|
||||
.init(type: HTMLGenerator.self),
|
||||
]
|
||||
|
||||
static func == (lhs: GeneratorOption, rhs: GeneratorOption) -> Bool {
|
||||
|
@ -54,7 +54,11 @@ public final class MakeColors: ParsableCommand, Context {
|
|||
let resolved = try data.resolve(key)
|
||||
switch color {
|
||||
case .color: print(key.insertCamelCaseSeparators(), resolved, separator: ": ")
|
||||
case .reference(let r): print("\(key.insertCamelCaseSeparators()) (@\(r.insertCamelCaseSeparators()))", resolved, separator: ": ")
|
||||
case let .reference(r): print(
|
||||
"\(key.insertCamelCaseSeparators()) (@\(r.insertCamelCaseSeparators()))",
|
||||
resolved,
|
||||
separator: ": "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,4 +77,3 @@ public final class MakeColors: ParsableCommand, Context {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ struct Color: CustomStringConvertible, Equatable {
|
|||
}
|
||||
|
||||
var description: String {
|
||||
return a != 0xFF ? String(format: "#%02X%02X%02X%02X", r, g, b, a): String(format: "#%02X%02X%02X", r, g, b)
|
||||
a != 0xFF ? String(format: "#%02X%02X%02X%02X", r, g, b, a) : String(format: "#%02X%02X%02X", r, g, b)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,10 @@ extension Dictionary where Key == String, Value == ColorDef {
|
|||
case nil:
|
||||
throw Errors.missingReference(name)
|
||||
|
||||
case .color(let color):
|
||||
case let .color(color):
|
||||
return color
|
||||
|
||||
case .reference(let referenced):
|
||||
case let .reference(referenced):
|
||||
return try resolve(referenced, visited: visited)
|
||||
}
|
||||
}
|
||||
|
@ -56,5 +56,4 @@ extension Dictionary where Key == String, Value == ColorDef {
|
|||
case let ((left, _), (right, _)): return left.localizedStandardCompare(right) == .orderedAscending
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import Foundation
|
|||
|
||||
private extension CharacterSet {
|
||||
static let hex = CharacterSet(charactersIn: "0123456789abcdef")
|
||||
static let name = alphanumerics.union(CharacterSet.init(charactersIn: "_/"))
|
||||
static let name = alphanumerics.union(CharacterSet(charactersIn: "_/"))
|
||||
}
|
||||
|
||||
private extension Collection {
|
||||
|
@ -16,22 +16,21 @@ private extension Collection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension Scanner {
|
||||
func string(_ s: String) -> Bool {
|
||||
return scanString(s) != nil
|
||||
scanString(s) != nil
|
||||
}
|
||||
|
||||
func color() -> Color? {
|
||||
if string("#"), let digits = scanCharacters(from: .hex) {
|
||||
switch digits.count {
|
||||
case 3, 4: //rgb(a)
|
||||
case 3, 4: // rgb(a)
|
||||
let digits = digits.chunks(size: 1)
|
||||
.compactMap { UInt8($0, radix: 16) }
|
||||
.map { $0 << 4 | $0 }
|
||||
return Color(digits)
|
||||
|
||||
case 6, 8: //rrggbb(aa)
|
||||
case 6, 8: // rrggbb(aa)
|
||||
let digits = digits.chunks(size: 2).compactMap { UInt8($0, radix: 16) }
|
||||
return Color(digits)
|
||||
|
||||
|
@ -76,9 +75,11 @@ extension Scanner {
|
|||
}
|
||||
|
||||
func colorLine() -> (String, ColorDef)? {
|
||||
guard let name = self.name(),
|
||||
let def = colorDef(),
|
||||
endOfLine() else {
|
||||
guard
|
||||
let name = self.name(),
|
||||
let def = colorDef(),
|
||||
endOfLine()
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
return (name, def)
|
||||
|
@ -92,7 +93,6 @@ extension Scanner {
|
|||
return true
|
||||
}
|
||||
|
||||
|
||||
func colorList() throws -> [String: ColorDef] {
|
||||
var result: [String: ColorDef] = [:]
|
||||
while !isAtEnd {
|
||||
|
@ -121,5 +121,3 @@ extension Scanner {
|
|||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue