Skip to content

Commit 5488199

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

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lib/services/doctor-service.ts

+43-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import {EOL} from "os";
44
import * as semver from "semver";
55
import * as path from "path";
6+
import child_process = require("child_process");
67

78
class DoctorService implements IDoctorService {
89
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
910

1011
constructor(private $androidToolsInfo: IAndroidToolsInfo,
1112
private $hostInfo: IHostInfo,
1213
private $logger: ILogger,
13-
private $sysInfo: ISysInfo) { }
14+
private $sysInfo: ISysInfo,
15+
private $childProcess: IChildProcess,
16+
private $fs: IFileSystem) { }
1417

1518
public printWarnings(): boolean {
1619
let result = false;
@@ -53,6 +56,15 @@ class DoctorService implements IDoctorService {
5356
result = true;
5457
}
5558

59+
if (sysInfo.xcodeVer && sysInfo.cocoapodVer) {
60+
let problemWithCocoaPods = this.verifyCocoaPods();
61+
if (problemWithCocoaPods) {
62+
this.$logger.warn("WARNING: There was a problem with CocoaPods");
63+
this.$logger.out("Verify that CocoaPods are configured properly.");
64+
result = true;
65+
}
66+
}
67+
5668
if (sysInfo.cocoapodVer && semver.valid(sysInfo.cocoapodVer) === null) {
5769
this.$logger.warn(`WARNING: CocoaPods version is not a valid semver version.`);
5870
this.$logger.out("You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
@@ -83,5 +95,35 @@ class DoctorService implements IDoctorService {
8395
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);
8496
}
8597
}
98+
99+
private verifyCocoaPods(): boolean {
100+
this.$logger.out("Verifying CocoaPods. This may take more than a minute, please be patient.");
101+
102+
let temp = require("temp");
103+
temp.track();
104+
let projDir = temp.mkdirSync("nativescript-check-cocoapods");
105+
this.$childProcess.spawnFromEvent(process.argv[0], [process.argv[1], "create", "test", "--path", projDir], "exit").wait();
106+
projDir = path.join(projDir, "test");
107+
let iosDir = path.join(projDir, "platforms", "ios");
108+
this.$childProcess.spawnFromEvent(process.argv[0], [process.argv[1], "platform", "add", "ios", "--path", projDir], "exit").wait();
109+
this.$fs.writeFile(
110+
path.join(iosDir, "Podfile"),
111+
"pod 'AFNetworking', '~> 1.0'\n"
112+
).wait();
113+
114+
try {
115+
let proc: child_process.ChildProcess = this.$childProcess.spawnFromEvent(
116+
"pod",
117+
["install"],
118+
"exit",
119+
{stdio: "inherit", cwd: iosDir},
120+
{ throwError: true }
121+
).wait();
122+
123+
return !(this.$fs.exists(path.join(iosDir, "")).wait());
124+
} catch(err) {
125+
return true;
126+
}
127+
}
86128
}
87129
$injector.register("doctorService", DoctorService);

0 commit comments

Comments
 (0)