Skip to content

Commit 1aab90a

Browse files
committed
make build script better
1 parent 91e6483 commit 1aab90a

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

build.swift

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55

66
import Foundation
77

8+
/// Map from scheme names to framework names.
9+
/// Hopefully can avoid hard-coding this in the future
10+
let schemes = [
11+
"FirebaseDatabaseUI",
12+
"FirebaseAuthUI",
13+
"FirebaseFacebookAuthUI",
14+
"FirebaseGoogleAuthUI",
15+
"FirebaseTwitterAuthUI",
16+
]
17+
18+
let staticLibs = [
19+
"Database": "FirebaseDatabaseUI",
20+
"Auth" : "FirebaseAuthUI",
21+
"Facebook": "FirebaseFacebookAuthUI",
22+
"Google" : "FirebaseGoogleAuthUI",
23+
"Twitter" : "FirebaseTwitterAuthUI",
24+
]
25+
826
// TODO: Use NSFileManager instead of all these awful
927
// manual path appendings and mkdir/mv/cp
1028

1129
let DerivedDataDir = "artifacts/"
12-
let BuiltProductsDir = DerivedDataDir + "FirebaseUIFrameworks/"
30+
let BuiltProductsDir = "FirebaseUIFrameworks/"
1331

1432
// TODO: DRY out these NSTask functions
1533

@@ -93,22 +111,6 @@ struct Build {
93111

94112
let sdks = ["iphoneos", "iphonesimulator"]
95113

96-
/// Map from scheme names to framework names.
97-
/// Hopefully can avoid hard-coding this in the future
98-
let schemes = [
99-
"FirebaseDatabaseUI",
100-
"FirebaseAuthUI",
101-
"FirebaseFacebookAuthUI",
102-
"FirebaseGoogleAuthUI",
103-
]
104-
105-
let staticLibs = [
106-
"Database": "FirebaseDatabaseUI",
107-
"Auth" : "FirebaseAuthUI",
108-
"Facebook": "FirebaseFacebookAuthUI",
109-
"Google" : "FirebaseGoogleAuthUI",
110-
]
111-
112114
// make folder structure for built products
113115
schemes.forEach { scheme in
114116
let schemeDir = BuiltProductsDir + scheme
@@ -202,4 +204,33 @@ lipos.forEach { $0.launch() }
202204
// copy license file
203205
cp(from: "LICENSE", to: BuiltProductsDir)
204206

207+
// clean up build artifacts afterward
208+
209+
/// Moves files to trash
210+
func rm(path: String, isDirectory: Bool) -> Void {
211+
let url = NSURL(fileURLWithPath: path, isDirectory: isDirectory)
212+
let fileManager = NSFileManager()
213+
do {
214+
try fileManager.trashItemAtURL(url, resultingItemURL: nil)
215+
} catch (let error) {
216+
print(fileManager.currentDirectoryPath)
217+
print(error)
218+
exit(1)
219+
}
220+
}
221+
222+
func zip(input: String, output: String) -> Void {
223+
let task = NSTask()
224+
task.launchPath = "/usr/bin/zip"
225+
task.arguments = ["-r", "-9", output, input]
226+
task.launch()
227+
task.waitUntilExit()
228+
guard task.terminationStatus == 0 else { exit(task.terminationStatus) }
229+
}
230+
231+
zip("FirebaseUIFrameworks", output: "FirebaseUIFrameworks.zip")
232+
233+
rm(DerivedDataDir, isDirectory: true)
234+
rm(BuiltProductsDir, isDirectory: true)
235+
205236
exit(0)

0 commit comments

Comments
 (0)