This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App] Run pod init on xcode projects
- Loading branch information
1 parent
b635b48
commit a3e79fc
Showing
5 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// CPPodfileInitController.swift | ||
// CocoaPods | ||
// | ||
// Created by Daniel Tomlinson on 10/02/2016. | ||
// Copyright © 2016 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum CPPodfileInitErrors: ErrorType { | ||
case CommandError(String) | ||
case NSURLError | ||
|
||
var message: String { | ||
switch self { | ||
case .CommandError(let s): return s | ||
case .NSURLError: return "NSURL unexpectedly nil" | ||
} | ||
} | ||
} | ||
|
||
public class CPPodfileInitController: NSObject, CPCLITaskDelegate { | ||
private var task: CPCLITask! | ||
private let completionHandler: (NSURL?, CPPodfileInitErrors?) -> () | ||
private let output = NSMutableAttributedString() | ||
private let projectURL: NSURL | ||
|
||
init(xcodeprojURL: NSURL, completionHandler: (podfileURL: NSURL?, error: CPPodfileInitErrors?) -> ()) { | ||
self.completionHandler = completionHandler | ||
self.projectURL = xcodeprojURL | ||
|
||
super.init() | ||
let task = CPCLITask(workingDirectory: xcodeprojURL.URLByDeletingLastPathComponent!.path, | ||
command: "init", | ||
delegate: self, | ||
qualityOfService: .UserInitiated) | ||
self.task = task | ||
|
||
self.task.run() | ||
} | ||
|
||
public func task(task: CPCLITask!, didUpdateOutputContents updatedOutput: NSAttributedString!) { | ||
output.appendAttributedString(updatedOutput) | ||
} | ||
|
||
public func taskCompleted(task: CPCLITask!) { | ||
guard task.finishedSuccessfully() else { | ||
self.callbackWithError(CPPodfileInitErrors.CommandError(self.output.string)) | ||
return | ||
} | ||
|
||
guard let podfileURL = projectURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("Podfile") where NSFileManager().fileExistsAtPath(podfileURL.path ?? "") | ||
else { | ||
self.callbackWithError(CPPodfileInitErrors.NSURLError) | ||
return | ||
} | ||
|
||
callbackWithSuccess(podfileURL) | ||
} | ||
|
||
private func callbackWithError(error: CPPodfileInitErrors) { | ||
dispatch_async(dispatch_get_main_queue()) { | ||
self.completionHandler(nil, error) | ||
} | ||
} | ||
|
||
private func callbackWithSuccess(url: NSURL) { | ||
dispatch_async(dispatch_get_main_queue()) { | ||
self.completionHandler(url, nil) | ||
} | ||
} | ||
} |