forked from yonaskolb/XcodeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetSource.swift
More file actions
179 lines (155 loc) · 5.61 KB
/
TargetSource.swift
File metadata and controls
179 lines (155 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import Foundation
import JSONUtilities
import PathKit
public struct TargetSource: Equatable {
public static let optionalDefault = false
public var path: String {
didSet {
path = (path as NSString).standardizingPath
}
}
public var name: String?
public var group: String?
public var compilerFlags: [String]
public var excludes: [String]
public var excludePatterns: [NSRegularExpression]
public var includes: [String]
public var type: SourceType?
public var optional: Bool
public var buildPhase: BuildPhaseSpec?
public var headerVisibility: HeaderVisibility?
public var createIntermediateGroups: Bool?
public var attributes: [String]
public var resourceTags: [String]
public var inferDestinationFiltersByPath: Bool?
public var destinationFilters: [SupportedDestination]?
public var brandName: String?
public enum HeaderVisibility: String {
case `public`
case `private`
case project
public var settingName: String {
switch self {
case .public: return "Public"
case .private: return "Private"
case .project: return "Project"
}
}
}
public init(
path: String,
name: String? = nil,
group: String? = nil,
compilerFlags: [String] = [],
excludes: [String] = [],
excludePatterns: [NSRegularExpression] = [],
includes: [String] = [],
type: SourceType? = nil,
optional: Bool = optionalDefault,
buildPhase: BuildPhaseSpec? = nil,
headerVisibility: HeaderVisibility? = nil,
createIntermediateGroups: Bool? = nil,
attributes: [String] = [],
resourceTags: [String] = [],
inferDestinationFiltersByPath: Bool? = nil,
destinationFilters: [SupportedDestination]? = nil,
brandName: String? = nil
) {
self.path = (path as NSString).standardizingPath
self.name = name
self.group = group
self.compilerFlags = compilerFlags
self.excludes = excludes
self.excludePatterns = excludePatterns
self.includes = includes
self.type = type
self.optional = optional
self.buildPhase = buildPhase
self.headerVisibility = headerVisibility
self.createIntermediateGroups = createIntermediateGroups
self.attributes = attributes
self.resourceTags = resourceTags
self.inferDestinationFiltersByPath = inferDestinationFiltersByPath
self.destinationFilters = destinationFilters
self.brandName = brandName
}
}
extension TargetSource: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self = TargetSource(path: value)
}
public init(extendedGraphemeClusterLiteral value: String) {
self = TargetSource(path: value)
}
public init(unicodeScalarLiteral value: String) {
self = TargetSource(path: value)
}
}
extension TargetSource: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
path = try jsonDictionary.json(atKeyPath: "path")
path = (path as NSString).standardizingPath // Done in two steps as the compiler can't figure out the types otherwise
name = jsonDictionary.json(atKeyPath: "name")
group = jsonDictionary.json(atKeyPath: "group")
let maybeCompilerFlagsString: String? = jsonDictionary.json(atKeyPath: "compilerFlags")
let maybeCompilerFlagsArray: [String]? = jsonDictionary.json(atKeyPath: "compilerFlags")
compilerFlags =
maybeCompilerFlagsArray ?? maybeCompilerFlagsString.map {
$0.split(separator: " ").map { String($0) }
} ?? []
headerVisibility = jsonDictionary.json(atKeyPath: "headerVisibility")
excludes = jsonDictionary.json(atKeyPath: "excludes") ?? []
let regexPatterns: [String] = jsonDictionary.json(atKeyPath: "excludePatterns") ?? []
excludePatterns = try regexPatterns.map({
try NSRegularExpression(pattern: $0)
})
includes = jsonDictionary.json(atKeyPath: "includes") ?? []
type = jsonDictionary.json(atKeyPath: "type")
optional = jsonDictionary.json(atKeyPath: "optional") ?? TargetSource.optionalDefault
if let string: String = jsonDictionary.json(atKeyPath: "buildPhase") {
buildPhase = try BuildPhaseSpec(string: string)
} else if let dict: JSONDictionary = jsonDictionary.json(atKeyPath: "buildPhase") {
buildPhase = try BuildPhaseSpec(jsonDictionary: dict)
}
createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups")
attributes = jsonDictionary.json(atKeyPath: "attributes") ?? []
resourceTags = jsonDictionary.json(atKeyPath: "resourceTags") ?? []
inferDestinationFiltersByPath = jsonDictionary.json(atKeyPath: "inferDestinationFiltersByPath")
if let destinationFilters: [SupportedDestination] = jsonDictionary.json(
atKeyPath: "destinationFilters")
{
self.destinationFilters = destinationFilters
}
brandName = jsonDictionary.json(atKeyPath: "brandName")
}
}
extension TargetSource: JSONEncodable {
public func toJSONValue() -> Any {
var dict: [String: Any?] = [
"compilerFlags": compilerFlags,
"excludes": excludes,
"includes": includes,
"name": name,
"group": group,
"headerVisibility": headerVisibility?.rawValue,
"type": type?.rawValue,
"buildPhase": buildPhase?.toJSONValue(),
"createIntermediateGroups": createIntermediateGroups,
"resourceTags": resourceTags,
"path": path,
"inferDestinationFiltersByPath": inferDestinationFiltersByPath,
"destinationFilters": destinationFilters?.map { $0.rawValue },
]
if optional != TargetSource.optionalDefault {
dict["optional"] = optional
}
return dict
}
}
extension TargetSource: PathContainer {
static var pathProperties: [PathProperty] {
[
.string("path")
]
}
}