Skip to content

Commit b33c9da

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

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lib/services/doctor-service.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class DoctorService implements IDoctorService {
1010
constructor(private $androidToolsInfo: IAndroidToolsInfo,
1111
private $hostInfo: IHostInfo,
1212
private $logger: ILogger,
13-
private $sysInfo: ISysInfo) { }
13+
private $sysInfo: ISysInfo,
14+
private $childProcess: IChildProcess,
15+
private $fs: IFileSystem) { }
1416

1517
public printWarnings(): boolean {
1618
let result = false;
@@ -53,6 +55,15 @@ class DoctorService implements IDoctorService {
5355
result = true;
5456
}
5557

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

0 commit comments

Comments
 (0)