forked from zenangst/Spots
-
Notifications
You must be signed in to change notification settings - Fork 6
/
update.swift
executable file
·71 lines (55 loc) · 2.11 KB
/
update.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
#!/usr/bin/env xcrun swift
import Foundation
struct System {
static func execute(command: String, _ arguments: String = "") {
guard let command = which(command: command) else { return }
task(command: command, arguments)
}
private static func which(command: String, _ arguments: String? = nil) -> String? {
let task = Process()
task.launchPath = "/usr/bin/which"
task.arguments = [command]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String?
return output?.components(separatedBy: "\n").first
}
private static func task(command: String, _ arguments: String? = nil) {
let task = Process()
task.launchPath = command
if let arguments = arguments, !arguments.isEmpty {
task.arguments = arguments.components(separatedBy: " ")
}
let stdOut = Pipe()
task.standardOutput = stdOut
let stdErr = Pipe()
task.standardError = stdErr
let handler = { (file: FileHandle!) -> Void in
let data = file.availableData
guard let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
else { return}
print(output.components(separatedBy: "\n").first!)
}
stdErr.fileHandleForReading.readabilityHandler = handler
stdOut.fileHandleForReading.readabilityHandler = handler
task.terminationHandler = { (task: Process?) -> () in
stdErr.fileHandleForReading.readabilityHandler = nil
stdOut.fileHandleForReading.readabilityHandler = nil
}
task.launch()
task.waitUntilExit()
}
}
if let rootPath = ProcessInfo.processInfo.environment["PWD"] {
var error: NSError? = nil
do {
let directories = try FileManager().contentsOfDirectory(atPath: "\(rootPath)/Examples")
for directory in directories where directory.characters.first != "." {
var isDir : ObjCBool = false
FileManager().changeCurrentDirectoryPath("\(rootPath)/Examples/\(directory)")
System.execute(command: "pod", "update --no-repo-update")
}
} catch {}
}