gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
修訂 | c18bdde6c419289c79816f3c5287eeefbb39e931 (tree) |
---|---|
時間 | 2018-05-25 22:36:36 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
<<< でカレントディレクトリを設定できるようにした
@@ -61,8 +61,9 @@ final class Carthage { | ||
61 | 61 | throw CarthageError.commandNotFound |
62 | 62 | } |
63 | 63 | |
64 | - let carthage = Process() <<< carthageURL.path <<< ["bootstrap"] | |
65 | - carthage.currentDirectoryPath = cartfile.deletingLastPathComponent().path | |
64 | + let carthage = Process() <<< ExcutableURL(url: carthageURL) | |
65 | + <<< ["bootstrap"] | |
66 | + <<< cartfile.deletingLastPathComponent() | |
66 | 67 | |
67 | 68 | carthage >>> { output, error in |
68 | 69 |
@@ -61,8 +61,9 @@ final class CocoaPods { | ||
61 | 61 | throw CarthageError.commandNotFound |
62 | 62 | } |
63 | 63 | |
64 | - let pod = Process() <<< podURL.path <<< ["install"] | |
65 | - pod.currentDirectoryPath = podfile.deletingLastPathComponent().path | |
64 | + let pod = Process() <<< ExcutableURL(url: podURL) | |
65 | + <<< ["install"] | |
66 | + <<< podfile.deletingLastPathComponent() | |
66 | 67 | |
67 | 68 | pod >>> { output, error in |
68 | 69 |
@@ -10,7 +10,7 @@ import Foundation | ||
10 | 10 | |
11 | 11 | func existCommand(_ commandName: String) -> Bool { |
12 | 12 | |
13 | - let which = Process() <<< "/usr/bin/which" <<< [commandName] | |
13 | + let which = Process() <<< ExcutableURL(fileURLWithPath: "/usr/bin/which") <<< [commandName] | |
14 | 14 | |
15 | 15 | if let currentPath = which.environment?["PATH"] { |
16 | 16 |
@@ -26,7 +26,7 @@ func existCommand(_ commandName: String) -> Bool { | ||
26 | 26 | |
27 | 27 | func commandPath(_ commandName: String) -> URL? { |
28 | 28 | |
29 | - let which = Process() <<< "/usr/bin/which" <<< [commandName] | |
29 | + let which = Process() <<< ExcutableURL(fileURLWithPath: "/usr/bin/which") <<< [commandName] | |
30 | 30 | |
31 | 31 | if let currentPath = which.environment?["PATH"] { |
32 | 32 |
@@ -42,6 +42,7 @@ func commandPath(_ commandName: String) -> URL? { | ||
42 | 42 | let lines = output.lines |
43 | 43 | |
44 | 44 | guard let path = lines.first else { |
45 | + | |
45 | 46 | return nil |
46 | 47 | } |
47 | 48 |
@@ -87,9 +87,9 @@ final class Git { | ||
87 | 87 | throw GitError.other("URL is invalid") |
88 | 88 | } |
89 | 89 | |
90 | - let git = Process() <<< gitURL.path <<< args | |
91 | - | |
92 | - git.currentDirectoryPath = workingURL.path | |
90 | + let git = Process() <<< ExcutableURL(url: gitURL) | |
91 | + <<< args | |
92 | + <<< workingURL | |
93 | 93 | |
94 | 94 | let errorString = git >>> { (stdout, stderr) -> String in |
95 | 95 |
@@ -108,7 +108,6 @@ final class Git { | ||
108 | 108 | |
109 | 109 | throw GitError.gitError(git.terminationStatus, errorString) |
110 | 110 | } |
111 | - | |
112 | 111 | } |
113 | 112 | |
114 | 113 | private func clone() throws { |
@@ -177,6 +176,5 @@ final class Git { | ||
177 | 176 | } |
178 | 177 | |
179 | 178 | return url.lastPathComponent |
180 | - | |
181 | 179 | } |
182 | 180 | } |
@@ -14,22 +14,41 @@ struct Output { | ||
14 | 14 | private let fileHandle: FileHandle |
15 | 15 | |
16 | 16 | init(fileHandle: FileHandle) { |
17 | + | |
17 | 18 | self.fileHandle = fileHandle |
18 | 19 | } |
19 | 20 | |
20 | 21 | var data: Data { |
22 | + | |
21 | 23 | return fileHandle.readDataToEndOfFile() |
22 | 24 | } |
23 | 25 | |
24 | 26 | var string: String? { |
27 | + | |
25 | 28 | return String(data: data, encoding: .utf8) |
26 | 29 | } |
27 | 30 | |
28 | 31 | var lines: [String] { |
32 | + | |
29 | 33 | return string?.components(separatedBy: "\n") ?? [] |
30 | 34 | } |
31 | 35 | } |
32 | 36 | |
37 | +struct ExcutableURL { | |
38 | + | |
39 | + let url: URL | |
40 | + | |
41 | + init(fileURLWithPath path: String) { | |
42 | + | |
43 | + url = URL(fileURLWithPath: path) | |
44 | + } | |
45 | + | |
46 | + init(url: URL) { | |
47 | + | |
48 | + self.url = url | |
49 | + } | |
50 | +} | |
51 | + | |
33 | 52 | precedencegroup ArgumentPrecedence { |
34 | 53 | |
35 | 54 | associativity: left |
@@ -38,9 +57,17 @@ precedencegroup ArgumentPrecedence { | ||
38 | 57 | infix operator <<< : ArgumentPrecedence |
39 | 58 | |
40 | 59 | /// Processにexecutable pathを設定する。 |
41 | -func <<< (lhs: Process, rhs: String) -> Process { | |
60 | +func <<< (lhs: Process, rhs: ExcutableURL) -> Process { | |
61 | + | |
62 | + if #available(macOS 10.13, *) { | |
63 | + | |
64 | + lhs.executableURL = rhs.url | |
65 | + | |
66 | + } else { | |
67 | + | |
68 | + lhs.launchPath = rhs.url.path | |
69 | + } | |
42 | 70 | |
43 | - lhs.launchPath = rhs | |
44 | 71 | return lhs |
45 | 72 | } |
46 | 73 |
@@ -48,6 +75,22 @@ func <<< (lhs: Process, rhs: String) -> Process { | ||
48 | 75 | func <<< (lhs: Process, rhs: [String]) -> Process { |
49 | 76 | |
50 | 77 | lhs.arguments = rhs |
78 | + | |
79 | + return lhs | |
80 | +} | |
81 | + | |
82 | +/// Current directoryを設定する。 | |
83 | +func <<< (lhs: Process, rhs: URL) -> Process { | |
84 | + | |
85 | + if #available(macOS 10.13, *) { | |
86 | + | |
87 | + lhs.currentDirectoryURL = rhs | |
88 | + | |
89 | + } else { | |
90 | + | |
91 | + lhs.currentDirectoryPath = rhs.path | |
92 | + } | |
93 | + | |
51 | 94 | return lhs |
52 | 95 | } |
53 | 96 |
@@ -33,7 +33,6 @@ final class ProjectBuilder { | ||
33 | 33 | } |
34 | 34 | |
35 | 35 | self.info = info |
36 | - | |
37 | 36 | } |
38 | 37 | |
39 | 38 | var productURL: URL { return info.productURL } |
@@ -52,8 +51,10 @@ final class ProjectBuilder { | ||
52 | 51 | throw ProjectBuilderError.other("URL is Invalid.") |
53 | 52 | } |
54 | 53 | |
55 | - let xcodebuild = Process() <<< builderURL.path <<< info.arguments | |
56 | - xcodebuild.currentDirectoryPath = info.projectURL.path | |
54 | + let xcodebuild = Process() <<< ExcutableURL(url: builderURL) | |
55 | + <<< info.arguments | |
56 | + <<< info.projectURL | |
57 | + | |
57 | 58 | xcodebuild >>> { stdout, stderr in |
58 | 59 | |
59 | 60 | let log = LogStocker("xcodebuild.log") |
@@ -68,6 +69,4 @@ final class ProjectBuilder { | ||
68 | 69 | throw ProjectBuilderError.commandFail |
69 | 70 | } |
70 | 71 | } |
71 | - | |
72 | - | |
73 | 72 | } |