Skip to content

Commit 5ec1b66

Browse files
Add platforms to the warnings and update the doctor checks
1 parent 010cd27 commit 5ec1b66

File tree

3 files changed

+125
-20
lines changed

3 files changed

+125
-20
lines changed

lib/doctor.ts

+30-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IosLocalBuildRequirements } from "./local-build-requirements/ios-local-
77
import { Helpers } from "./helpers";
88
import * as semver from "semver";
99

10-
export class Doctor {
10+
export class Doctor implements NativeScriptDoctor.IDoctor {
1111
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
1212

1313
constructor(private androidLocalBuildRequirements: AndroidLocalBuildRequirements,
@@ -38,7 +38,8 @@ export class Doctor {
3838
additionalInformation: "For Android-related operations, the AppBuilder CLI will use a built-in version of adb." + EOL
3939
+ "To avoid possible issues with the native Android emulator, Genymotion or connected" + EOL
4040
+ "Android devices, verify that you have installed the latest Android SDK and" + EOL
41-
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL
41+
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL,
42+
platforms: [Constants.ANDROID_PLATFORM_NAME]
4243
});
4344
}
4445

@@ -47,7 +48,8 @@ export class Doctor {
4748
warning: "WARNING: The Android SDK is not installed or is not configured properly.",
4849
additionalInformation: "You will not be able to run your apps in the native emulator. To be able to run apps" + EOL
4950
+ "in the native Android emulator, verify that you have installed the latest Android SDK " + EOL
50-
+ "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL
51+
+ "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL,
52+
platforms: [Constants.ANDROID_PLATFORM_NAME]
5153
});
5254
}
5355

@@ -56,23 +58,34 @@ export class Doctor {
5658
result.push({
5759
warning: "WARNING: Xcode is not installed or is not configured properly.",
5860
additionalInformation: "You will not be able to build your projects for iOS or run them in the iOS Simulator." + EOL
59-
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode." + EOL
61+
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode." + EOL,
62+
platforms: [Constants.IOS_PLATFORM_NAME]
6063
});
6164
}
6265

6366
if (!sysInfoData.xcodeprojGemLocation) {
6467
result.push({
6568
warning: "WARNING: xcodeproj gem is not installed or is not configured properly.",
6669
additionalInformation: "You will not be able to build your projects for iOS." + EOL
67-
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed xcodeproj." + EOL
70+
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed xcodeproj." + EOL,
71+
platforms: [Constants.IOS_PLATFORM_NAME]
6872
});
6973
}
7074

7175
if (!sysInfoData.cocoaPodsVer) {
7276
result.push({
7377
warning: "WARNING: CocoaPods is not installed or is not configured properly.",
7478
additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
75-
+ "To be able to build such projects, verify that you have installed CocoaPods."
79+
+ "To be able to build such projects, verify that you have installed CocoaPods.",
80+
platforms: [Constants.IOS_PLATFORM_NAME]
81+
});
82+
}
83+
84+
if (sysInfoData.cocoaPodsVer && sysInfoData.isCocoaPodsUpdateRequired) {
85+
result.push({
86+
warning: "WARNING: CocoaPods update required.",
87+
additionalInformation: `You are using CocoaPods version ${sysInfoData.cocoaPodsVer} which does not support Xcode ${sysInfoData.xcodeVer} yet.${EOL}${EOL}You can update your cocoapods by running $sudo gem install cocoapods from a terminal.${EOL}${EOL}In order for the NativeScript CLI to be able to work correctly with this setup you need to install xcproj command line tool and add it to your PATH.Xcproj can be installed with homebrew by running $ brew install xcproj from the terminal`,
88+
platforms: [Constants.IOS_PLATFORM_NAME]
7689
});
7790
}
7891

@@ -81,7 +94,8 @@ export class Doctor {
8194
if (!isCocoaPodsWorkingCorrectly) {
8295
result.push({
8396
warning: "WARNING: There was a problem with CocoaPods",
84-
additionalInformation: "Verify that CocoaPods are configured properly."
97+
additionalInformation: "Verify that CocoaPods are configured properly.",
98+
platforms: [Constants.IOS_PLATFORM_NAME]
8599
});
86100
}
87101
}
@@ -90,13 +104,15 @@ export class Doctor {
90104
result.push({
91105
warning: `WARNING: Your current CocoaPods version is earlier than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`,
92106
additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
93-
+ `To be able to build such projects, verify that you have at least ${Doctor.MIN_SUPPORTED_POD_VERSION} version installed.`
107+
+ `To be able to build such projects, verify that you have at least ${Doctor.MIN_SUPPORTED_POD_VERSION} version installed.`,
108+
platforms: [Constants.IOS_PLATFORM_NAME]
94109
});
95110
}
96111
} else {
97112
result.push({
98113
warning: "NOTE: You can develop for iOS only on Mac OS X systems.",
99-
additionalInformation: "To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later." + EOL
114+
additionalInformation: "To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later." + EOL,
115+
platforms: [Constants.IOS_PLATFORM_NAME]
100116
});
101117
}
102118

@@ -107,7 +123,8 @@ export class Doctor {
107123
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
108124
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
109125
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)" + EOL
110-
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + EOL
126+
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + EOL,
127+
platforms: [Constants.ANDROID_PLATFORM_NAME]
111128
});
112129
}
113130

@@ -116,7 +133,8 @@ export class Doctor {
116133
warning: "WARNING: Git is not installed or not configured properly.",
117134
additionalInformation: "You will not be able to create and work with Screen Builder projects." + EOL
118135
+ "To be able to work with Screen Builder projects, download and install Git as described" + EOL
119-
+ "in https://git-scm.com/downloads and add the git executable to your PATH." + EOL
136+
+ "in https://git-scm.com/downloads and add the git executable to your PATH." + EOL,
137+
platforms: Constants.SUPPORTED_PLATFORMS
120138
});
121139
}
122140

@@ -133,7 +151,7 @@ export class Doctor {
133151
}
134152

135153
if (!this.isPlatformSupported(platform)) {
136-
throw new Error(`Platform ${platform} is not supported. The supported platforms are: ${Constants.SUPPORTED_PLATFORMS.join(", ")}`);
154+
throw new Error(`Platform ${platform} is not supported.The supported platforms are: ${Constants.SUPPORTED_PLATFORMS.join(", ")} `);
137155
}
138156
}
139157
}

lib/sys-info.ts

+45-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { platform } from "os";
88
import * as path from "path";
99
import * as osenv from "osenv";
1010
import * as temp from "temp";
11+
import * as semver from "semver";
1112

12-
export class SysInfo {
13+
export class SysInfo implements NativeScriptDoctor.ISysInfo {
1314
// Different java has different format for `java -version` command.
1415
private static JAVA_VERSION_REGEXP = /(?:openjdk|java) version \"((?:\d+\.)+(?:\d+))/i;
1516

@@ -37,7 +38,9 @@ export class SysInfo {
3738
private gradleVerCache: string;
3839
private sysInfoCache: NativeScriptDoctor.ISysInfoData;
3940
private isCocoaPodsWorkingCorrectlyCache: boolean = null;
40-
private nativeScriptCliVersion: string;
41+
private nativeScriptCliVersionCache: string;
42+
private xcprojInfoCache: NativeScriptDoctor.IXcprojInfo;
43+
private isCocoaPodsUpdateRequiredCache: boolean = null;
4144

4245
constructor(private childProcess: ChildProcess,
4346
private fileSystem: FileSystem,
@@ -218,7 +221,7 @@ export class SysInfo {
218221
const output = await this.execCommand("gradle -v");
219222
const matches = SysInfo.GRADLE_VERSION_REGEXP.exec(output);
220223

221-
this.gradleVerCache = matches && matches[1];
224+
this.gradleVerCache = matches && matches[1];
222225
}
223226

224227
return this.gradleVerCache;
@@ -253,6 +256,7 @@ export class SysInfo {
253256
result.gradleVer = await this.getGradleVersion();
254257
result.isCocoaPodsWorkingCorrectly = await this.isCocoaPodsWorkingCorrectly();
255258
result.nativeScriptCliVersion = await this.getNativeScriptCliVersion();
259+
result.isCocoaPodsUpdateRequired = await this.isCocoaPodsUpdateRequired();
256260

257261
this.sysInfoCache = result;
258262
}
@@ -286,12 +290,47 @@ export class SysInfo {
286290
}
287291

288292
public async getNativeScriptCliVersion(): Promise<string> {
289-
if (!this.nativeScriptCliVersion) {
293+
if (!this.nativeScriptCliVersionCache) {
290294
const output = await this.execCommand("tns --version");
291-
this.nativeScriptCliVersion = output.trim();
295+
this.nativeScriptCliVersionCache = output ? output.trim() : output;
292296
}
293297

294-
return this.nativeScriptCliVersion;
298+
return this.nativeScriptCliVersionCache;
299+
}
300+
301+
public async getXcprojInfo(): Promise<NativeScriptDoctor.IXcprojInfo> {
302+
if (!this.xcprojInfoCache) {
303+
const cocoaPodsVersion = await this.getCocoaPodsVersion();
304+
const xcodeVersion = await this.getXcodeVersion();
305+
306+
// CocoaPods with version lower than 1.0.0 don't support Xcode 7.3 yet
307+
// https://github.com/CocoaPods/CocoaPods/issues/2530#issuecomment-210470123
308+
// as a result of this all .pbxprojects touched by CocoaPods get converted to XML plist format
309+
const shouldUseXcproj = cocoaPodsVersion && !!(semver.lt(cocoaPodsVersion, "1.0.0") && semver.gte(xcodeVersion, "7.3.0"));
310+
let xcprojAvailable: boolean;
311+
312+
if (shouldUseXcproj) {
313+
// If that's the case we can use xcproj gem to convert them back to ASCII plist format
314+
xcprojAvailable = !!(await this.exec("xcproj --version"))
315+
}
316+
317+
this.xcprojInfoCache = { shouldUseXcproj, xcprojAvailable };
318+
}
319+
320+
return this.xcprojInfoCache;
321+
}
322+
323+
public async isCocoaPodsUpdateRequired(): Promise<boolean> {
324+
if (this.isCocoaPodsUpdateRequiredCache === null) {
325+
let xcprojInfo = await this.getXcprojInfo();
326+
if (xcprojInfo.shouldUseXcproj && !xcprojInfo.xcprojAvailable) {
327+
this.isCocoaPodsUpdateRequiredCache = true;
328+
} else {
329+
this.isCocoaPodsUpdateRequiredCache = false;
330+
}
331+
}
332+
333+
return this.isCocoaPodsUpdateRequiredCache;
295334
}
296335

297336
private async exec(cmd: string, execOptions?: ExecOptions): Promise<IProcessInfo> {

typings/interfaces.ts

+50-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ declare module NativeScriptDoctor {
9999
*/
100100
getNativeScriptCliVersion(): Promise<string>;
101101

102+
/**
103+
* Checks if xcproj is required to build projects and if it is installed.
104+
* @return {Promise<IXcprojInfo>} Returns the collected information aboud xcproj.
105+
*/
106+
getXcprojInfo(): Promise<IXcprojInfo>;
107+
108+
/**
109+
* Checks if the current version of CocoaPods is compatible with the installed Xcode.
110+
* @return {boolean} true if an update us require.
111+
*/
112+
isCocoaPodsUpdateRequired(): Promise<boolean>;
113+
102114
/**
103115
* Returns the whole system information.
104116
* @return {Promise<ISysInfoData>} The system information.
@@ -253,16 +265,52 @@ declare module NativeScriptDoctor {
253265
* @type {string}
254266
*/
255267
nativeScriptCliVersion: string;
268+
269+
/**
270+
* Information about xcproj.
271+
* @type {string}
272+
*/
273+
xcprojInfo: IXcprojInfo
274+
275+
/**
276+
* true if the system requires xcproj to build projects successfully and the CocoaPods version is not compatible with the Xcode.
277+
*/
278+
isCocoaPodsUpdateRequired: boolean;
256279
}
257280

258281
/**
259282
* Describes warning returned from nativescript-doctor check.
260283
*/
261284
interface IWarning {
262-
/** The warning. */
285+
/** The warning.
286+
* @type {string}
287+
*/
263288
warning: string;
264-
/** Additional information for the warning. */
289+
290+
/** Additional information for the warning.
291+
* @type {string}
292+
*/
265293
additionalInformation: string;
294+
295+
/** The platforms which are affected by this warning.
296+
* @type {string[]}
297+
*/
298+
platforms: string[];
299+
}
300+
301+
/**
302+
* Describes information about xcproj brew formula.
303+
*/
304+
interface IXcprojInfo {
305+
/**
306+
* Determines whether the system needs xcproj to execute ios builds sucessfully.
307+
*/
308+
shouldUseXcproj: boolean;
309+
310+
/**
311+
* Determines whether xcproj can be called from the command line.
312+
*/
313+
xcprojAvailable: boolean;
266314
}
267315

268316
/**

0 commit comments

Comments
 (0)