gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
Revisión | 9396c04ed9faffd38288e3d2ffd4766b55af98ba (tree) |
---|---|
Tiempo | 2018-04-08 10:47:15 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
ProjectFinderクラスを関数群に変更
@@ -39,7 +39,7 @@ struct BuildInfo { | ||
39 | 39 | |
40 | 40 | init?(projectURL: URL) { |
41 | 41 | |
42 | - guard let projectFileURL = ProjectFinder.find(in: projectURL) | |
42 | + guard let projectFileURL = find(in: projectURL) | |
43 | 43 | else { return nil } |
44 | 44 | |
45 | 45 | self.projectURL = projectURL |
@@ -8,39 +8,44 @@ | ||
8 | 8 | |
9 | 9 | import Foundation |
10 | 10 | |
11 | - | |
12 | -final class ProjectFinder { | |
11 | +func find(in url: URL, depth: Int = 1) -> URL? { | |
13 | 12 | |
14 | - static func find(in url: URL, depth: Int = 1) -> URL? { | |
15 | - | |
16 | - guard depth != 0 else { return nil } | |
17 | - | |
18 | - guard let contents = try? FileManager.default.contentsOfDirectory(at: url, | |
19 | - includingPropertiesForKeys: [.isDirectoryKey]) | |
20 | - else { | |
21 | - return nil | |
22 | - } | |
23 | - | |
24 | - if let url = contents.lazy.filter({ $0.pathExtension == "xcworkspace" }).first { | |
25 | - | |
26 | - return url | |
27 | - } | |
28 | - | |
29 | - if let url = contents.lazy.filter({ $0.pathExtension == "xcodeproj" }).first { | |
30 | - | |
31 | - return url | |
32 | - } | |
13 | + if let workspace = findFile(pattern: "\\w*\\.xcworkspace$", in: url, depth: depth) { | |
33 | 14 | |
15 | + return workspace | |
16 | + } | |
17 | + | |
18 | + if let project = findFile(pattern: "\\w*\\.xcodeproj$", in: url, depth: depth) { | |
34 | 19 | |
35 | - func isDir(_ url: URL) -> Bool { | |
36 | - | |
37 | - return (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false | |
38 | - } | |
20 | + return project | |
21 | + } | |
22 | + | |
23 | + return nil | |
24 | +} | |
25 | + | |
26 | +func findFile(pattern: String, in url: URL, depth: Int = 1) -> URL? { | |
27 | + | |
28 | + guard depth != 0 else { return nil } | |
29 | + | |
30 | + guard let contents = try? FileManager.default.contentsOfDirectory(at: url, | |
31 | + includingPropertiesForKeys: [.isDirectoryKey]) | |
32 | + else { | |
33 | + return nil | |
34 | + } | |
35 | + | |
36 | + if let url = contents.lazy.filter({ $0.path.match(pattern) }).first { | |
39 | 37 | |
40 | - return contents.lazy | |
41 | - .filter(isDir) | |
42 | - .flatMap { find(in: $0, depth: depth - 1) } | |
43 | - .first | |
38 | + return url | |
39 | + } | |
40 | + | |
41 | + | |
42 | + func isDir(_ url: URL) -> Bool { | |
44 | 43 | |
44 | + return (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false | |
45 | 45 | } |
46 | + | |
47 | + return contents.lazy | |
48 | + .filter(isDir) | |
49 | + .flatMap { findFile(pattern: pattern, in: $0, depth: depth - 1) } | |
50 | + .first | |
46 | 51 | } |
@@ -34,4 +34,18 @@ class AppBuilderWithGitTests: XCTestCase { | ||
34 | 34 | |
35 | 35 | XCTAssertFalse(".xcodeproj.copy".match("\\w*\\.xcodeproj$")) |
36 | 36 | } |
37 | + | |
38 | + | |
39 | + func testFileFinder() { | |
40 | + | |
41 | + let bundleURL = Bundle.main.bundleURL | |
42 | + | |
43 | + XCTAssertNotNil(findFile(pattern: "Contents", in: bundleURL)) | |
44 | + | |
45 | + XCTAssertNotNil(findFile(pattern: "PkgInfo", in: bundleURL, depth: 3)) | |
46 | + | |
47 | + XCTAssertNil(findFile(pattern: "pkgInfo", in: bundleURL, depth: 3)) | |
48 | + | |
49 | + | |
50 | + } | |
37 | 51 | } |