|
3 | 3 | import {EOL} from "os";
|
4 | 4 | import * as semver from "semver";
|
5 | 5 | import * as path from "path";
|
| 6 | +import child_process = require("child_process"); |
6 | 7 |
|
7 | 8 | class DoctorService implements IDoctorService {
|
8 | 9 | private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
|
9 | 10 |
|
10 | 11 | constructor(private $androidToolsInfo: IAndroidToolsInfo,
|
11 | 12 | private $hostInfo: IHostInfo,
|
12 | 13 | private $logger: ILogger,
|
13 |
| - private $sysInfo: ISysInfo) { } |
| 14 | + private $sysInfo: ISysInfo, |
| 15 | + private $childProcess: IChildProcess, |
| 16 | + private $fs: IFileSystem) { } |
14 | 17 |
|
15 | 18 | public printWarnings(): boolean {
|
16 | 19 | let result = false;
|
@@ -53,6 +56,15 @@ class DoctorService implements IDoctorService {
|
53 | 56 | result = true;
|
54 | 57 | }
|
55 | 58 |
|
| 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 | + |
56 | 68 | if (sysInfo.cocoapodVer && semver.valid(sysInfo.cocoapodVer) === null) {
|
57 | 69 | this.$logger.warn(`WARNING: CocoaPods version is not a valid semver version.`);
|
58 | 70 | 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 {
|
83 | 95 | 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);
|
84 | 96 | }
|
85 | 97 | }
|
| 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 | + } |
86 | 128 | }
|
87 | 129 | $injector.register("doctorService", DoctorService);
|
0 commit comments