gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
Revisión | 9ad183fc348f873d3191ae9026411690273484c1 (tree) |
---|---|
Tiempo | 2018-04-08 14:59:27 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
必要ならCocoaPodsを実行するようにした
@@ -18,6 +18,7 @@ | ||
18 | 18 | F41A45141F3E9DFA0066F83D /* BuildInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45131F3E9DFA0066F83D /* BuildInfo.swift */; }; |
19 | 19 | F41A45161F3EC0950066F83D /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45151F3EC0950066F83D /* WindowController.swift */; }; |
20 | 20 | F41A45181F401D4B0066F83D /* LogStocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45171F401D4B0066F83D /* LogStocker.swift */; }; |
21 | + F45853192079DDBE007B251A /* CocoaPods.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45853182079DDBE007B251A /* CocoaPods.swift */; }; | |
21 | 22 | F4DDB3B42077BB41004781AE /* CommandFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DDB3B32077BB41004781AE /* CommandFinder.swift */; }; |
22 | 23 | F4DDB3B62077BBB2004781AE /* Process-extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DDB3B52077BBB2004781AE /* Process-extensions.swift */; }; |
23 | 24 | F4DDB3BE2077BD2B004781AE /* AppBuilderWithGitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DDB3BD2077BD2B004781AE /* AppBuilderWithGitTests.swift */; }; |
@@ -49,6 +50,7 @@ | ||
49 | 50 | F41A45131F3E9DFA0066F83D /* BuildInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildInfo.swift; sourceTree = "<group>"; }; |
50 | 51 | F41A45151F3EC0950066F83D /* WindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; }; |
51 | 52 | F41A45171F401D4B0066F83D /* LogStocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogStocker.swift; sourceTree = "<group>"; }; |
53 | + F45853182079DDBE007B251A /* CocoaPods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CocoaPods.swift; sourceTree = "<group>"; }; | |
52 | 54 | F4DDB3B32077BB41004781AE /* CommandFinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandFinder.swift; sourceTree = "<group>"; }; |
53 | 55 | F4DDB3B52077BBB2004781AE /* Process-extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Process-extensions.swift"; sourceTree = "<group>"; }; |
54 | 56 | F4DDB3BB2077BD2B004781AE /* AppBuilderWithGitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AppBuilderWithGitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
@@ -110,6 +112,7 @@ | ||
110 | 112 | F41A45051F3D83AE0066F83D /* ProjectFinder.swift */, |
111 | 113 | F4DDB3C92079A3DB004781AE /* String-extensions.swift */, |
112 | 114 | F4DDB3C72079A209004781AE /* Carthage.swift */, |
115 | + F45853182079DDBE007B251A /* CocoaPods.swift */, | |
113 | 116 | F41A44F21F3D6B1B0066F83D /* Assets.xcassets */, |
114 | 117 | F41A44F41F3D6B1B0066F83D /* Main.storyboard */, |
115 | 118 | F41A44F71F3D6B1B0066F83D /* Info.plist */, |
@@ -235,6 +238,7 @@ | ||
235 | 238 | F4DDB3B62077BBB2004781AE /* Process-extensions.swift in Sources */, |
236 | 239 | F41A45041F3D782A0066F83D /* Git.swift in Sources */, |
237 | 240 | F4DDB3CA2079A3DB004781AE /* String-extensions.swift in Sources */, |
241 | + F45853192079DDBE007B251A /* CocoaPods.swift in Sources */, | |
238 | 242 | F41A44F11F3D6B1B0066F83D /* ViewController.swift in Sources */, |
239 | 243 | F41A45141F3E9DFA0066F83D /* BuildInfo.swift in Sources */, |
240 | 244 | F4DDB3C82079A209004781AE /* Carthage.swift in Sources */, |
@@ -0,0 +1,81 @@ | ||
1 | +// | |
2 | +// CocoaPods.swift | |
3 | +// AppBuilderWithGit | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2018/04/08. | |
6 | +// Copyright © 2018年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +import Foundation | |
10 | + | |
11 | +enum CocoaPodsError: Error { | |
12 | + | |
13 | + case commandNotFound | |
14 | + | |
15 | + case commandFail | |
16 | +} | |
17 | + | |
18 | +final class CocoaPods { | |
19 | + | |
20 | + let baseURL: URL | |
21 | + | |
22 | + init(_ url: URL) { | |
23 | + | |
24 | + self.baseURL = url | |
25 | + } | |
26 | + | |
27 | + private var podfileURL: URL? { | |
28 | + | |
29 | + return findFile(pattern: "^Podfile$", in: baseURL, depth: 2) | |
30 | + } | |
31 | + | |
32 | + private var podURL: URL? { | |
33 | + | |
34 | + return commandPath("pod") | |
35 | + } | |
36 | + | |
37 | + func checkCocoaPods() -> Bool { | |
38 | + | |
39 | + guard podfileURL != nil else { | |
40 | + | |
41 | + return false | |
42 | + } | |
43 | + | |
44 | + guard podURL != nil else { | |
45 | + | |
46 | + return false | |
47 | + } | |
48 | + | |
49 | + return true | |
50 | + } | |
51 | + | |
52 | + func execute() throws { | |
53 | + | |
54 | + guard let podfile = podfileURL else { | |
55 | + | |
56 | + return | |
57 | + } | |
58 | + | |
59 | + guard let podURL = podURL else { | |
60 | + | |
61 | + throw CarthageError.commandNotFound | |
62 | + } | |
63 | + | |
64 | + let pod = Process() <<< podURL.path <<< ["install"] | |
65 | + pod.currentDirectoryPath = podfile.deletingLastPathComponent().path | |
66 | + | |
67 | + pod >>> { output, error in | |
68 | + | |
69 | + let log = LogStocker("cocoapods.log") | |
70 | + log?.write(output.data) | |
71 | + log?.write(error.data) | |
72 | + } | |
73 | + pod.waitUntilExit() | |
74 | + | |
75 | + if pod.terminationStatus != 0 { | |
76 | + | |
77 | + throw CarthageError.commandFail | |
78 | + } | |
79 | + } | |
80 | +} | |
81 | + |
@@ -117,6 +117,11 @@ extension ViewController { | ||
117 | 117 | return |
118 | 118 | } |
119 | 119 | |
120 | + guard self.cocoaPods(gitCloner.repository) else { | |
121 | + | |
122 | + return | |
123 | + } | |
124 | + | |
120 | 125 | self.build(gitCloner.repository) |
121 | 126 | |
122 | 127 | case let .gitError(stat, mess): |
@@ -157,6 +162,33 @@ extension ViewController { | ||
157 | 162 | } |
158 | 163 | } |
159 | 164 | |
165 | + private func cocoaPods(_ url: URL) -> Bool { | |
166 | + | |
167 | + message = "Checking CocoaPods." | |
168 | + | |
169 | + do { | |
170 | + | |
171 | + let pod = CocoaPods(url) | |
172 | + | |
173 | + guard pod.checkCocoaPods() else { | |
174 | + | |
175 | + return true | |
176 | + } | |
177 | + | |
178 | + message = "Building frameworks with CocoaPods." | |
179 | + | |
180 | + try pod.execute() | |
181 | + | |
182 | + return true | |
183 | + | |
184 | + } catch { | |
185 | + | |
186 | + message = "Fail to CocoaPods." | |
187 | + | |
188 | + return false | |
189 | + } | |
190 | + } | |
191 | + | |
160 | 192 | private func build(_ url: URL) { |
161 | 193 | |
162 | 194 | message = "Building Project." |