forked from yonaskolb/XcodeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildScript.swift
More file actions
118 lines (103 loc) · 4.11 KB
/
BuildScript.swift
File metadata and controls
118 lines (103 loc) · 4.11 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
import Foundation
import JSONUtilities
public struct BuildScript: Equatable {
public static let runOnlyWhenInstallingDefault = false
public static let showEnvVarsDefault = true
public static let basedOnDependencyAnalysisDefault = true
public var script: ScriptType
public var name: String?
public var shell: String?
public var inputFiles: [String]
public var outputFiles: [String]
public var inputFileLists: [String]
public var outputFileLists: [String]
public var runOnlyWhenInstalling: Bool
public let showEnvVars: Bool
public let basedOnDependencyAnalysis: Bool
public let discoveredDependencyFile: String?
public enum ScriptType: Equatable {
case path(String)
case script(String)
}
public init(
script: ScriptType,
name: String? = nil,
inputFiles: [String] = [],
outputFiles: [String] = [],
inputFileLists: [String] = [],
outputFileLists: [String] = [],
shell: String? = nil,
runOnlyWhenInstalling: Bool = runOnlyWhenInstallingDefault,
showEnvVars: Bool = showEnvVarsDefault,
basedOnDependencyAnalysis: Bool = basedOnDependencyAnalysisDefault,
discoveredDependencyFile: String? = nil
) {
self.script = script
self.name = name
self.inputFiles = inputFiles
self.outputFiles = outputFiles
self.inputFileLists = inputFileLists
self.outputFileLists = outputFileLists
self.shell = shell
self.runOnlyWhenInstalling = runOnlyWhenInstalling
self.showEnvVars = showEnvVars
self.basedOnDependencyAnalysis = basedOnDependencyAnalysis
self.discoveredDependencyFile = discoveredDependencyFile
}
}
extension BuildScript: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
name = jsonDictionary.json(atKeyPath: "name")
inputFiles = jsonDictionary.json(atKeyPath: "inputFiles") ?? []
outputFiles = jsonDictionary.json(atKeyPath: "outputFiles") ?? []
inputFileLists = jsonDictionary.json(atKeyPath: "inputFileLists") ?? []
outputFileLists = jsonDictionary.json(atKeyPath: "outputFileLists") ?? []
if let string: String = jsonDictionary.json(atKeyPath: "script") {
script = .script(string)
} else {
let path: String = try jsonDictionary.json(atKeyPath: "path")
script = .path(path)
}
shell = jsonDictionary.json(atKeyPath: "shell")
runOnlyWhenInstalling = jsonDictionary.json(atKeyPath: "runOnlyWhenInstalling") ?? BuildScript.runOnlyWhenInstallingDefault
showEnvVars = jsonDictionary.json(atKeyPath: "showEnvVars") ?? BuildScript.showEnvVarsDefault
basedOnDependencyAnalysis = jsonDictionary.json(atKeyPath: "basedOnDependencyAnalysis") ?? BuildScript.basedOnDependencyAnalysisDefault
discoveredDependencyFile = jsonDictionary.json(atKeyPath: "discoveredDependencyFile")
}
}
extension BuildScript: JSONEncodable {
public func toJSONValue() -> Any {
var dict: [String: Any?] = [
"inputFiles": inputFiles,
"inputFileLists": inputFileLists,
"outputFiles": outputFiles,
"outputFileLists": outputFileLists,
"runOnlyWhenInstalling": runOnlyWhenInstalling,
"name": name,
"shell": shell,
]
if showEnvVars != BuildScript.showEnvVarsDefault {
dict["showEnvVars"] = showEnvVars
}
if basedOnDependencyAnalysis != BuildScript.basedOnDependencyAnalysisDefault {
dict["basedOnDependencyAnalysis"] = basedOnDependencyAnalysis
}
switch script {
case .path(let string):
dict["path"] = string
case .script(let string):
dict["script"] = string
}
if let discoveredDependencyFile = discoveredDependencyFile {
dict["discoveredDependencyFile"] = discoveredDependencyFile
}
return dict
}
}
extension BuildScript: PathContainer {
static var pathProperties: [PathProperty] {
[
.string("path"),
]
}
}