Skip to content

Commit bb77cd2

Browse files
author
Fatme
authored
Merge pull request #28 from NativeScript/fatme/info-messages
Introduce getInfos() method
2 parents ec3203a + 59b86a5 commit bb77cd2

File tree

4 files changed

+196
-104
lines changed

4 files changed

+196
-104
lines changed

lib/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ export class Constants {
77
"linux": "http://docs.nativescript.org/setup/ns-cli-setup/ns-setup-linux.html#system-requirements",
88
"darwin": "http://docs.nativescript.org/setup/ns-cli-setup/ns-setup-os-x.html#system-requirements",
99
};
10+
public static INFO_TYPE_NAME = "info";
11+
public static WARNING_TYPE_NAME = "warning";
1012
}

lib/doctor.ts

+159-103
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Constants } from "./constants";
2-
import { EOL } from "os";
2+
import { EOL, platform } from "os";
33
import { HostInfo } from "./host-info";
44
import { AndroidLocalBuildRequirements } from "./local-build-requirements/android-local-build-requirements";
55
import { IosLocalBuildRequirements } from "./local-build-requirements/ios-local-build-requirements";
@@ -28,150 +28,206 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
2828
return false;
2929
}
3030

31-
public async getWarnings(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IWarning[]> {
32-
let result: NativeScriptDoctor.IWarning[] = [];
31+
public async getInfos(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IInfo[]> {
32+
let result: NativeScriptDoctor.IInfo[] = [];
3333
const sysInfoData = await this.sysInfo.getSysInfo(config);
3434

35-
const androidHomeValidationErrors = this.androidToolsInfo.validateAndroidHomeEnvVariable();
36-
if (androidHomeValidationErrors.length > 0) {
37-
result = result.concat(androidHomeValidationErrors);
38-
}
39-
40-
if (!sysInfoData.adbVer) {
41-
result.push({
42-
warning: "WARNING: adb from the Android SDK is not installed or is not configured properly. ",
35+
result = result.concat(
36+
this.processValidationErrors({
37+
warnings: this.androidToolsInfo.validateAndroidHomeEnvVariable(),
38+
infoMessage: "Your ANDROID_HOME environment variable is set and points to correct directory.",
39+
platforms: [Constants.ANDROID_PLATFORM_NAME]
40+
}),
41+
this.processSysInfoItem({
42+
item: sysInfoData.adbVer,
43+
infoMessage: "Your adb from the Android SDK is correctly installed.",
44+
warningMessage: "adb from the Android SDK is not installed or is not configured properly. ",
4345
additionalInformation: "For Android-related operations, the NativeScript CLI will use a built-in version of adb." + EOL
44-
+ "To avoid possible issues with the native Android emulator, Genymotion or connected" + EOL
45-
+ "Android devices, verify that you have installed the latest Android SDK and" + EOL
46-
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL,
46+
+ "To avoid possible issues with the native Android emulator, Genymotion or connected" + EOL
47+
+ "Android devices, verify that you have installed the latest Android SDK and" + EOL
48+
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements",
4749
platforms: [Constants.ANDROID_PLATFORM_NAME]
48-
});
49-
}
50-
51-
if (!sysInfoData.isAndroidSdkConfiguredCorrectly) {
52-
result.push({
53-
warning: "WARNING: The Android SDK is not installed or is not configured properly.",
50+
}),
51+
this.processSysInfoItem({
52+
item: sysInfoData.isAndroidSdkConfiguredCorrectly,
53+
infoMessage: "The Android SDK is installed.",
54+
warningMessage: "The Android SDK is not installed or is not configured properly.",
5455
additionalInformation: "You will not be able to run your apps in the native emulator. To be able to run apps" + EOL
55-
+ "in the native Android emulator, verify that you have installed the latest Android SDK " + EOL
56-
+ "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + EOL,
56+
+ "in the native Android emulator, verify that you have installed the latest Android SDK " + EOL
57+
+ "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements",
5758
platforms: [Constants.ANDROID_PLATFORM_NAME]
58-
});
59-
}
60-
61-
const androidToolsInfoValidationErrors = this.androidToolsInfo.validateInfo();
62-
if (androidToolsInfoValidationErrors.length > 0) {
63-
result = result.concat(androidToolsInfoValidationErrors);
64-
}
65-
66-
const javacValidationErrors = this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion);
67-
if (javacValidationErrors.length > 0) {
68-
result = result.concat(javacValidationErrors);
69-
}
59+
}),
60+
this.processValidationErrors({
61+
warnings: this.androidToolsInfo.validateInfo(),
62+
infoMessage: "A compatible Android SDK for compilation is found.",
63+
platforms: [Constants.ANDROID_PLATFORM_NAME]
64+
}),
65+
this.processValidationErrors({
66+
warnings: this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion),
67+
infoMessage: "Javac is installed and is configured properly.",
68+
platforms: [Constants.ANDROID_PLATFORM_NAME]
69+
})
70+
);
7071

7172
if (this.hostInfo.isDarwin) {
72-
if (!sysInfoData.xcodeVer) {
73-
result.push({
74-
warning: "WARNING: Xcode is not installed or is not configured properly.",
73+
result = result.concat(
74+
this.processSysInfoItem({
75+
item: sysInfoData.xcodeVer,
76+
infoMessage: "Xcode is installed and is configured properly.",
77+
warningMessage: "Xcode is not installed or is not configured properly.",
7578
additionalInformation: "You will not be able to build your projects for iOS or run them in the iOS Simulator." + EOL
76-
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode." + EOL,
79+
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode.",
7780
platforms: [Constants.IOS_PLATFORM_NAME]
78-
});
79-
}
80-
81-
if (!sysInfoData.xcodeprojLocation) {
82-
result.push({
83-
warning: "WARNING: xcodeproj gem is not installed or is not configured properly.",
81+
}),
82+
this.processSysInfoItem({
83+
item: sysInfoData.xcodeprojLocation,
84+
infoMessage: "xcodeproj is installed and is configured properly.",
85+
warningMessage: "xcodeproj is not installed or is not configured properly.",
8486
additionalInformation: "You will not be able to build your projects for iOS." + EOL
85-
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed xcodeproj." + EOL,
87+
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed xcodeproj.",
8688
platforms: [Constants.IOS_PLATFORM_NAME]
87-
});
88-
}
89-
90-
if (!sysInfoData.cocoaPodsVer) {
91-
result.push({
92-
warning: "WARNING: CocoaPods is not installed or is not configured properly.",
89+
}),
90+
this.processSysInfoItem({
91+
item: sysInfoData.cocoaPodsVer,
92+
infoMessage: "CocoaPods are installed.",
93+
warningMessage: "CocoaPods is not installed or is not configured properly.",
9394
additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
94-
+ "To be able to build such projects, verify that you have installed CocoaPods.",
95+
+ "To be able to build such projects, verify that you have installed CocoaPods.",
9596
platforms: [Constants.IOS_PLATFORM_NAME]
96-
});
97-
}
98-
99-
if (sysInfoData.cocoaPodsVer && sysInfoData.isCocoaPodsUpdateRequired) {
100-
result.push({
101-
warning: "WARNING: CocoaPods update required.",
97+
}),
98+
this.processSysInfoItem({
99+
item: !sysInfoData.cocoaPodsVer || !sysInfoData.isCocoaPodsUpdateRequired,
100+
infoMessage: "CocoaPods update is not required.",
101+
warningMessage: "CocoaPods update required.",
102102
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`,
103103
platforms: [Constants.IOS_PLATFORM_NAME]
104-
});
105-
}
104+
})
105+
);
106106

107107
if (sysInfoData.xcodeVer && sysInfoData.cocoaPodsVer) {
108108
let isCocoaPodsWorkingCorrectly = await this.sysInfo.isCocoaPodsWorkingCorrectly();
109-
if (!isCocoaPodsWorkingCorrectly) {
110-
result.push({
111-
warning: "WARNING: There was a problem with CocoaPods",
109+
result = result.concat(
110+
this.processSysInfoItem({
111+
item: isCocoaPodsWorkingCorrectly,
112+
infoMessage: "CocoaPods are configured properly.",
113+
warningMessage: "There was a problem with CocoaPods",
112114
additionalInformation: "Verify that CocoaPods are configured properly.",
113-
platforms: [Constants.IOS_PLATFORM_NAME]
114-
});
115-
}
115+
platforms: [Constants.IOS_PLATFORM_NAME],
116+
})
117+
);
116118
}
117119

118-
if (sysInfoData.cocoaPodsVer && semver.valid(sysInfoData.cocoaPodsVer) && semver.lt(sysInfoData.cocoaPodsVer, Doctor.MIN_SUPPORTED_POD_VERSION)) {
119-
result.push({
120-
warning: `WARNING: Your current CocoaPods version is earlier than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`,
120+
result = result.concat(
121+
this.processSysInfoItem({
122+
item: !sysInfoData.cocoaPodsVer || !semver.valid(sysInfoData.cocoaPodsVer) || !semver.lt(sysInfoData.cocoaPodsVer, Doctor.MIN_SUPPORTED_POD_VERSION),
123+
infoMessage: `Your current CocoaPods version is newer than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`,
124+
warningMessage: `Your current CocoaPods version is earlier than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`,
121125
additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + EOL
122-
+ `To be able to build such projects, verify that you have at least ${Doctor.MIN_SUPPORTED_POD_VERSION} version installed.`,
126+
+ `To be able to build such projects, verify that you have at least ${Doctor.MIN_SUPPORTED_POD_VERSION} version installed.`,
123127
platforms: [Constants.IOS_PLATFORM_NAME]
124-
});
125-
}
126-
127-
if (!sysInfoData.pythonInfo.isInstalled) {
128-
result.push({
129-
warning: `WARNING: Couldn't retrieve installed python packages.`,
128+
}),
129+
this.processSysInfoItem({
130+
item: sysInfoData.pythonInfo.isInstalled,
131+
infoMessage: "Python installed and configured correctly.",
132+
warningMessage: `Couldn't retrieve installed python packages.`,
130133
additionalInformation: "We cannot verify your python installation is setup correctly. Please, make sure you have both 'python' and 'pip' installed." + EOL
131134
+ `Error while validating Python packages. Error is: ${sysInfoData.pythonInfo.installationErrorMessage}`,
132135
platforms: [Constants.IOS_PLATFORM_NAME]
133-
});
134-
}
135-
136-
if (!sysInfoData.pythonInfo.isSixPackageInstalled) {
137-
result.push({
138-
warning: `WARNING: The Python 'six' package not found.`,
136+
}),
137+
this.processSysInfoItem({
138+
item: sysInfoData.pythonInfo.isSixPackageInstalled,
139+
infoMessage: `The Python 'six' package is found.`,
140+
warningMessage: `The Python 'six' package not found.`,
139141
additionalInformation: "This package is required by the Debugger library (LLDB) for iOS. You can install it by first making sure you have pip installed and then running 'pip install six' from the terminal.",
140142
platforms: [Constants.IOS_PLATFORM_NAME]
141-
});
142-
}
143+
})
144+
);
143145
} else {
144146
result.push({
145-
warning: "NOTE: You can develop for iOS only on Mac OS X systems.",
146-
additionalInformation: "To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later." + EOL,
147-
platforms: [Constants.IOS_PLATFORM_NAME]
147+
message: "NOTE: You can develop for iOS only on Mac OS X systems.",
148+
additionalInformation: "To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later.",
149+
platforms: [Constants.IOS_PLATFORM_NAME],
150+
type: Constants.INFO_TYPE_NAME
148151
});
149152
}
150153

151-
if (!sysInfoData.javacVersion) {
152-
result.push({
153-
warning: "WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.",
154+
result = result.concat(
155+
this.processSysInfoItem({
156+
item: sysInfoData.javacVersion,
157+
infoMessage: "The Java Development Kit (JDK) is installed and is configured properly.",
158+
warningMessage: "The Java Development Kit (JDK) is not installed or is not configured properly.",
154159
additionalInformation: "You will not be able to work with the Android SDK and you might not be able" + EOL
155-
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
156-
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
157-
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)." + EOL,
160+
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
161+
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
162+
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8).",
158163
platforms: [Constants.ANDROID_PLATFORM_NAME]
159-
});
160-
}
161-
162-
if (!sysInfoData.gitVer) {
163-
result.push({
164-
warning: "WARNING: Git is not installed or not configured properly.",
164+
}),
165+
this.processSysInfoItem({
166+
item: sysInfoData.gitVer,
167+
infoMessage: "Git is installed and is configured properly.",
168+
warningMessage: "Git is not installed or not configured properly.",
165169
additionalInformation: "You will not be able to create and work with Screen Builder projects." + EOL
166-
+ "To be able to work with Screen Builder projects, download and install Git as described" + EOL
167-
+ "in https://git-scm.com/downloads and add the git executable to your PATH." + EOL,
170+
+ "To be able to work with Screen Builder projects, download and install Git as described" + EOL
171+
+ "in https://git-scm.com/downloads and add the git executable to your PATH.",
168172
platforms: Constants.SUPPORTED_PLATFORMS
169-
});
170-
}
173+
})
174+
);
171175

172176
return result;
173177
}
174178

179+
public async getWarnings(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IWarning[]> {
180+
const info = await this.getInfos(config);
181+
return info.filter(item => item.type === Constants.WARNING_TYPE_NAME)
182+
.map(item => this.convertInfoToWarning(item));
183+
}
184+
185+
private processSysInfoItem(data: { item: string | boolean, infoMessage: string, warningMessage: string, additionalInformation?: string, platforms: string[] }): NativeScriptDoctor.IInfo {
186+
if (!data.item) {
187+
return {
188+
message: `WARNING: ${data.warningMessage}`,
189+
additionalInformation: data.additionalInformation,
190+
platforms: data.platforms,
191+
type: Constants.WARNING_TYPE_NAME
192+
}
193+
}
194+
195+
return {
196+
message: `${data.infoMessage}`,
197+
platforms: data.platforms,
198+
type: Constants.INFO_TYPE_NAME
199+
};
200+
}
201+
202+
private processValidationErrors(data: { warnings: NativeScriptDoctor.IWarning[], infoMessage: string, platforms: string[]}): NativeScriptDoctor.IInfo[] {
203+
if (data.warnings.length > 0) {
204+
return data.warnings.map(warning => this.convertWarningToInfo(warning));
205+
}
206+
207+
return [{
208+
message: data.infoMessage,
209+
platforms: data.platforms,
210+
type: Constants.INFO_TYPE_NAME
211+
}];
212+
}
213+
214+
private convertWarningToInfo(warning: NativeScriptDoctor.IWarning): NativeScriptDoctor.IInfo {
215+
return {
216+
message: warning.warning,
217+
additionalInformation: warning.additionalInformation,
218+
platforms: warning.platforms,
219+
type: Constants.WARNING_TYPE_NAME
220+
};
221+
}
222+
223+
private convertInfoToWarning(info: NativeScriptDoctor.IInfo): NativeScriptDoctor.IWarning {
224+
return {
225+
warning: info.message,
226+
additionalInformation: info.additionalInformation,
227+
platforms: info.platforms
228+
};
229+
}
230+
175231
private isPlatformSupported(platform: string): boolean {
176232
return Constants.SUPPORTED_PLATFORMS.map(pl => pl.toLowerCase()).indexOf(platform.toLowerCase()) !== -1;
177233
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-doctor",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"description": "Library that helps identifying if the environment can be used for development of {N} apps.",
55
"main": "lib/index.js",
66
"types": "./typings/nativescript-doctor.d.ts",

typings/interfaces.ts

+34
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ declare module NativeScriptDoctor {
174174
* @return {Promise<IWarning[]>} Array of all the warnings from all checks. If there are no warnings will return empty array.
175175
*/
176176
getWarnings(): Promise<IWarning[]>;
177+
178+
/**
179+
* Executes all checks for the current environment and returns the info from each check
180+
* @return {Promise<IInfo[]>} Array of all the infos from all checks.
181+
*/
182+
getInfos(): Promise<IInfo[]>;
177183
}
178184

179185
interface ISysInfoData {
@@ -347,6 +353,32 @@ declare module NativeScriptDoctor {
347353
platforms: string[];
348354
}
349355

356+
interface IInfo {
357+
/**
358+
* The message.
359+
* @type {string}
360+
*/
361+
message: string;
362+
363+
/**
364+
* Additional information for the warning.
365+
* @type {string}
366+
*/
367+
additionalInformation?: string;
368+
369+
/**
370+
* The platforms which are affected by this warning.
371+
* @type {string[]}
372+
*/
373+
platforms: string[];
374+
375+
/**
376+
* The warning.
377+
* @type {string} // can be warning, note or info
378+
*/
379+
type: string;
380+
}
381+
350382
/**
351383
* Describes information about xcproj brew formula.
352384
*/
@@ -389,6 +421,8 @@ declare module NativeScriptDoctor {
389421
ANDROID_PLATFORM_NAME: string;
390422
IOS_PLATFORM_NAME: string;
391423
SUPPORTED_PLATFORMS: string[];
424+
INFO_TYPE_NAME: string;
425+
WARNING_TYPE_NAME: string;
392426
}
393427

394428
/**

0 commit comments

Comments
 (0)