-
Notifications
You must be signed in to change notification settings - Fork 1
/
Project.swift
174 lines (151 loc) · 4.99 KB
/
Project.swift
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
import ProjectDescription
import ProjectDescriptionHelpers
/*
+-------------+
| |
| App | Contains TuistSample App target and TuistSample unit-test target
| |
+------+-------------+-------+
| depends on |
| |
+----v-----+ +-----v-----+
| | | |
| Kit | | UI | Two independent frameworks to share code and start modularising your app
| | | |
+----------+ +-----------+
*/
// MARK: - Project
// Creates our project using a helper function defined in ProjectDescriptionHelpers
enum AppConfiguration: String {
case Debug
case Release
}
struct AppInfomation {
var name: String
var bundleId: String
var configuration: AppConfiguration
}
extension AppInfomation {
var configValue: String {
return configuration.rawValue
}
}
protocol ProjectFactory {
var projectName: String { get }
var targets: [Target] { get }
var deployment: DeploymentTarget { get }
var schemes: [Scheme] { get }
var setting: Settings { get }
func make() -> Project
}
class BaseProjectFactory: ProjectFactory {
let projectName: String = "Tooda"
var deployment: DeploymentTarget {
.iOS(targetVersion: "13.0", devices: .iphone)
}
var targets: [Target] {
[
Target(
name: projectName,
platform: .iOS,
product: .app,
bundleId: "com.tooda",
deploymentTarget: deployment,
infoPlist: "\(projectName)/Sources/SupportFiles/Info.plist",
sources: ["\(projectName)/Sources/**"],
resources: ["\(projectName)/Resources/**"],
entitlements: "\(projectName)/Sources/SupportFiles/Tooda.entitlements",
scripts: targetScripts,
dependencies: []
),
Target(
name: "\(projectName)Tests",
platform: .iOS,
product: .unitTests,
bundleId: "com.tooda.\(projectName)Tests",
deploymentTarget: deployment,
infoPlist: "\(projectName)Tests/Info.plist",
sources: ["\(projectName)Tests/**"],
resources: [],
dependencies: []
)
]
}
var schemes: [Scheme] { [
Scheme.init(
name: testAppinfo.name,
shared: true,
buildAction: .buildAction(targets: ["\(projectName)"]),
testAction: .targets(["\(projectName)"]),
runAction: .runAction(
configuration: .configuration("\(testAppinfo.configValue)"),
arguments: nil
)
),
Scheme.init(
name: releaseAppInfo.name,
shared: true,
buildAction: .buildAction(targets: ["\(projectName)"]),
testAction: .targets(["\(projectName)"]),
runAction: .runAction(
configuration: .configuration("\(releaseAppInfo.configValue)"),
arguments: nil
)
)
]}
var setting: Settings {
.settings(configurations: [
.debug(name: .configuration("Debug"),
settings: [
"Debug": "\(testAppinfo.configValue)",
"CODE_SIGN_STYLE": "Manual",
"CODE_SIGN_IDENTITY": "Apple Development",
"PROVISIONING_PROFILE_SPECIFIER": "match Development com.tooda",
"DEVELOPMENT_TEAM": "67SBNF2QS6"
],
xcconfig: .relativeToRoot("\(projectName)/Sources/SupportFiles/Configuration/\(testAppinfo.configValue).xcconfig")),
.release(name: .configuration("Release"),
settings: ["Release": "\(releaseAppInfo.configValue)"],
xcconfig: .relativeToRoot("\(projectName)/Sources/SupportFiles/Configuration/\(releaseAppInfo.configValue).xcconfig"))
])
}
func make() -> Project {
Project.init(name: self.projectName,
settings: self.setting,
targets: self.targets,
schemes: self.schemes,
fileHeaderTemplate: nil,
additionalFiles: [])
}
}
// MARK: App Schemes
extension BaseProjectFactory {
var releaseAppInfo: AppInfomation {
AppInfomation(name: "Tooda", bundleId: "com.tooda", configuration: .Release)
}
var testAppinfo: AppInfomation {
AppInfomation(name: "ToodaTest", bundleId: "com.tooda.test", configuration: .Debug)
}
}
extension BaseProjectFactory {
var targetScripts: [TargetScript] {
[
TargetScript.pre(script: "${PODS_ROOT}/Swiftlint/swiftlint", name: "Swiftlint")
]
}
}
// MARK: Test Code
extension BaseProjectFactory {
func aa() -> Configuration {
let configuration: [String: SettingValue] = [
"APP_NAME": "TodaTest",
"APP_IDENTIFIER": "com.tooda.test",
"APP_VERSION": "2.0.1",
"APP_BUILD": "1",
"MY_VALUE": "Hello"
]
// path can nil
return Configuration.debug(name: "Debug", settings: configuration, xcconfig: .relativeToRoot("\(projectName)/Sources/SupportFiles/Configuration/Debug.xcconfig"))
}
}
let project = BaseProjectFactory().make()