Skip to content

Commit 5cc9485

Browse files
committed
Verify CocoaPods
see #1294
1 parent 61c6b78 commit 5cc9485

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lib/services/doctor-service.ts

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

0 commit comments

Comments
 (0)