Skip to content

Commit 96112ef

Browse files
committed
Verify CocoaPods
see #1294
1 parent 61c6b78 commit 96112ef

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/services/doctor-service.ts

+46-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 $npm: INodePackageManager,
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,36 @@ 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+
108+
try {
109+
this.$npm.install("tns-ios", projDir).wait();
110+
let iosDir = path.join(projDir, "node_modules", "tns-ios", "framework");
111+
this.$fs.writeFile(
112+
path.join(iosDir, "Podfile"),
113+
"pod 'AFNetworking', '~> 1.0'\n"
114+
).wait();
115+
116+
let future = this.$childProcess.spawnFromEvent(
117+
this.$config.USE_POD_SANDBOX ? "sandbox-pod": "pod",
118+
["install"],
119+
"exit",
120+
{stdio: "inherit", cwd: iosDir},
121+
{ throwError: true }
122+
);
123+
124+
this.$progressIndicator.showProgressIndicator(future, 5000).wait();
125+
126+
return !(this.$fs.exists(path.join(iosDir, "__PROJECT_NAME__.xcworkspace")).wait());
127+
} catch(err) {
128+
return true;
129+
}
130+
}
86131
}
87132
$injector.register("doctorService", DoctorService);

0 commit comments

Comments
 (0)