forked from zenangst/Spots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.swift
executable file
·71 lines (55 loc) · 2.08 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) else { return }
task(command, arguments)
}
private static func which(command: String, _ arguments: String? = nil) -> String? {
let task = NSTask()
task.launchPath = "/usr/bin/which"
task.arguments = [command]
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: NSUTF8StringEncoding) as String?
return output?.componentsSeparatedByString("\n").first
}
private static func task(command: String, _ arguments: String? = nil) {
let task = NSTask()
task.launchPath = command
if let arguments = arguments where !arguments.isEmpty {
task.arguments = arguments.componentsSeparatedByString(" ")
}
let stdOut = NSPipe()
task.standardOutput = stdOut
let stdErr = NSPipe()
task.standardError = stdErr
let handler = { (file: NSFileHandle!) -> Void in
let data = file.availableData
guard let output = NSString(data: data, encoding: NSUTF8StringEncoding)
else { return}
print(output.componentsSeparatedByString("\n").first!)
}
stdErr.fileHandleForReading.readabilityHandler = handler
stdOut.fileHandleForReading.readabilityHandler = handler
task.terminationHandler = { (task: NSTask?) -> () in
stdErr.fileHandleForReading.readabilityHandler = nil
stdOut.fileHandleForReading.readabilityHandler = nil
}
task.launch()
task.waitUntilExit()
}
}
if let rootPath = NSProcessInfo.processInfo().environment["PWD"] {
var error: NSError? = nil
do {
let directories = try NSFileManager().contentsOfDirectoryAtPath("\(rootPath)/Examples")
for directory in directories where directory.characters.first != "." {
var isDir : ObjCBool = false
NSFileManager().changeCurrentDirectoryPath("\(rootPath)/Examples/\(directory)")
System.execute("pod", "update")
}
} catch {}
}