Skip to content

Commit 0ed851d

Browse files
committed
Verify CocoaPods
see #1294
1 parent 2bd272d commit 0ed851d

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/services/doctor-service.ts

+44-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ class DoctorService implements IDoctorService {
1010
constructor(private $androidToolsInfo: IAndroidToolsInfo,
1111
private $hostInfo: IHostInfo,
1212
private $logger: ILogger,
13-
private $sysInfo: ISysInfo) { }
13+
private $progressIndicator: IProgressIndicator,
14+
private $sysInfo: ISysInfo,
15+
private $childProcess: IChildProcess,
16+
private $config: IConfiguration,
17+
private $npmInstallationManager: INpmInstallationManager,
18+
private $fs: IFileSystem) { }
1419

1520
public printWarnings(): boolean {
1621
let result = false;
@@ -53,6 +58,15 @@ class DoctorService implements IDoctorService {
5358
result = true;
5459
}
5560

61+
if (sysInfo.xcodeVer && sysInfo.cocoapodVer) {
62+
let problemWithCocoaPods = this.verifyCocoaPods();
63+
if (problemWithCocoaPods) {
64+
this.$logger.warn("WARNING: There was a problem with CocoaPods");
65+
this.$logger.out("Verify that CocoaPods are configured properly.");
66+
result = true;
67+
}
68+
}
69+
5670
if (sysInfo.cocoapodVer && semver.valid(sysInfo.cocoapodVer) === null) {
5771
this.$logger.warn(`WARNING: CocoaPods version is not a valid semver version.`);
5872
this.$logger.out("You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
@@ -83,5 +97,34 @@ class DoctorService implements IDoctorService {
8397
this.$logger.out("TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies." + EOL);
8498
}
8599
}
100+
101+
private verifyCocoaPods(): boolean {
102+
this.$logger.out("Verifying CocoaPods. This may take more than a minute, please be patient.");
103+
104+
let temp = require("temp");
105+
temp.track();
106+
let projDir = temp.mkdirSync("nativescript-check-cocoapods");
107+
this.$npmInstallationManager.install("tns-ios", {version: "latest", pathToSave: projDir}).wait();
108+
this.$fs.writeFile(
109+
path.join(projDir, "Podfile"),
110+
"pod 'AFNetworking', '~> 1.0'\n"
111+
).wait();
112+
113+
try {
114+
let future = this.$childProcess.spawnFromEvent(
115+
this.$config.USE_POD_SANDBOX ? "sandbox-pod": "pod",
116+
["install"],
117+
"exit",
118+
{stdio: "inherit", cwd: projDir},
119+
{ throwError: true }
120+
);
121+
122+
this.$progressIndicator.showProgressIndicator(future, 5000).wait();
123+
124+
return !(this.$fs.exists(path.join(projDir, "test.xcworkspace")).wait());
125+
} catch(err) {
126+
return true;
127+
}
128+
}
86129
}
87130
$injector.register("doctorService", DoctorService);

0 commit comments

Comments
 (0)