mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
dfe7f28bcb
* Failing test for #975 * fixes #975 * chore: refactor to properly select a config from a collection with specific variant and config type chore: updated changelog * fix: lowercase compare on config variant names * fix CI * fix missing scheme for CI * fix schemes for CI * Update CHANGELOG.md Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> * Update Sources/ProjectSpec/Config.swift Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com> * - fix compilation issue - duplicated test for config variant name (uppercase/lowercase) Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
44 lines
1.2 KiB
Swift
44 lines
1.2 KiB
Swift
import Foundation
|
|
import JSONUtilities
|
|
|
|
public struct Config: Hashable {
|
|
public var name: String
|
|
public var type: ConfigType?
|
|
|
|
public init(name: String, type: ConfigType? = nil) {
|
|
self.name = name
|
|
self.type = type
|
|
}
|
|
|
|
public static var defaultConfigs: [Config] = [Config(name: ConfigType.debug.name, type: .debug), Config(name: ConfigType.release.name, type: .release)]
|
|
}
|
|
|
|
public enum ConfigType: String {
|
|
case debug
|
|
case release
|
|
|
|
public var name: String {
|
|
rawValue.prefix(1).uppercased() + rawValue.dropFirst()
|
|
}
|
|
}
|
|
|
|
public extension Collection where Element == Config {
|
|
func first(including configVariant: String, for type: ConfigType) -> Config? {
|
|
first(where: { $0.type == type && $0.name.variantName(for: $0.type) == configVariant })
|
|
}
|
|
}
|
|
|
|
private extension String {
|
|
func variantName(for configType: ConfigType?) -> String {
|
|
self.components(separatedBy: " ")
|
|
.compactMap { component in
|
|
if component.lowercased() == (configType?.name.lowercased() ?? "") {
|
|
return nil
|
|
}
|
|
return component
|
|
}
|
|
.joined(separator: " ")
|
|
.trimmingCharacters(in: CharacterSet.whitespaces)
|
|
}
|
|
}
|