• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用


Commit MetaInfo

Revisión9396c04ed9faffd38288e3d2ffd4766b55af98ba (tree)
Tiempo2018-04-08 10:47:15
Autormasakih <masakih@user...>
Commitermasakih

Log Message

ProjectFinderクラスを関数群に変更

Cambiar Resumen

Diferencia incremental

--- a/AppBuilderWithGit/BuildInfo.swift
+++ b/AppBuilderWithGit/BuildInfo.swift
@@ -39,7 +39,7 @@ struct BuildInfo {
3939
4040 init?(projectURL: URL) {
4141
42- guard let projectFileURL = ProjectFinder.find(in: projectURL)
42+ guard let projectFileURL = find(in: projectURL)
4343 else { return nil }
4444
4545 self.projectURL = projectURL
--- a/AppBuilderWithGit/ProjectFinder.swift
+++ b/AppBuilderWithGit/ProjectFinder.swift
@@ -8,39 +8,44 @@
88
99 import Foundation
1010
11-
12-final class ProjectFinder {
11+func find(in url: URL, depth: Int = 1) -> URL? {
1312
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) {
3314
15+ return workspace
16+ }
17+
18+ if let project = findFile(pattern: "\\w*\\.xcodeproj$", in: url, depth: depth) {
3419
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 {
3937
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 {
4443
44+ return (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
4545 }
46+
47+ return contents.lazy
48+ .filter(isDir)
49+ .flatMap { findFile(pattern: pattern, in: $0, depth: depth - 1) }
50+ .first
4651 }
--- a/AppBuilderWithGitTests/AppBuilderWithGitTests.swift
+++ b/AppBuilderWithGitTests/AppBuilderWithGitTests.swift
@@ -34,4 +34,18 @@ class AppBuilderWithGitTests: XCTestCase {
3434
3535 XCTAssertFalse(".xcodeproj.copy".match("\\w*\\.xcodeproj$"))
3636 }
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+ }
3751 }