|
1 | 1 | import { Constants } from "./constants";
|
2 |
| -import { EOL } from "os"; |
| 2 | +import { EOL, platform } from "os"; |
3 | 3 | import { HostInfo } from "./host-info";
|
4 | 4 | import { AndroidLocalBuildRequirements } from "./local-build-requirements/android-local-build-requirements";
|
5 | 5 | import { IosLocalBuildRequirements } from "./local-build-requirements/ios-local-build-requirements";
|
@@ -28,150 +28,206 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
|
28 | 28 | return false;
|
29 | 29 | }
|
30 | 30 |
|
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[] = []; |
33 | 33 | const sysInfoData = await this.sysInfo.getSysInfo(config);
|
34 | 34 |
|
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. ", |
43 | 45 | 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", |
47 | 49 | 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.", |
54 | 55 | 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", |
57 | 58 | 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 | + ); |
70 | 71 |
|
71 | 72 | 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.", |
75 | 78 | 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.", |
77 | 80 | 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.", |
84 | 86 | 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.", |
86 | 88 | 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.", |
93 | 94 | 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.", |
95 | 96 | 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.", |
102 | 102 | 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`,
|
103 | 103 | platforms: [Constants.IOS_PLATFORM_NAME]
|
104 |
| - }); |
105 |
| - } |
| 104 | + }) |
| 105 | + ); |
106 | 106 |
|
107 | 107 | if (sysInfoData.xcodeVer && sysInfoData.cocoaPodsVer) {
|
108 | 108 | 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", |
112 | 114 | additionalInformation: "Verify that CocoaPods are configured properly.",
|
113 |
| - platforms: [Constants.IOS_PLATFORM_NAME] |
114 |
| - }); |
115 |
| - } |
| 115 | + platforms: [Constants.IOS_PLATFORM_NAME], |
| 116 | + }) |
| 117 | + ); |
116 | 118 | }
|
117 | 119 |
|
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}.`, |
121 | 125 | 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.`, |
123 | 127 | 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.`, |
130 | 133 | additionalInformation: "We cannot verify your python installation is setup correctly. Please, make sure you have both 'python' and 'pip' installed." + EOL
|
131 | 134 | + `Error while validating Python packages. Error is: ${sysInfoData.pythonInfo.installationErrorMessage}`,
|
132 | 135 | 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.`, |
139 | 141 | 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.",
|
140 | 142 | platforms: [Constants.IOS_PLATFORM_NAME]
|
141 |
| - }); |
142 |
| - } |
| 143 | + }) |
| 144 | + ); |
143 | 145 | } else {
|
144 | 146 | 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 |
148 | 151 | });
|
149 | 152 | }
|
150 | 153 |
|
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.", |
154 | 159 | 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).", |
158 | 163 | 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.", |
165 | 169 | 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.", |
168 | 172 | platforms: Constants.SUPPORTED_PLATFORMS
|
169 |
| - }); |
170 |
| - } |
| 173 | + }) |
| 174 | + ); |
171 | 175 |
|
172 | 176 | return result;
|
173 | 177 | }
|
174 | 178 |
|
| 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 | + |
175 | 231 | private isPlatformSupported(platform: string): boolean {
|
176 | 232 | return Constants.SUPPORTED_PLATFORMS.map(pl => pl.toLowerCase()).indexOf(platform.toLowerCase()) !== -1;
|
177 | 233 | }
|
|
0 commit comments