Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 29202b5

Browse files
committed
Implement "doctor" command
See NativeScript/nativescript-cli#480
1 parent 37bacb6 commit 29202b5

File tree

3 files changed

+36
-110
lines changed

3 files changed

+36
-110
lines changed

bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ $injector.require("mobileHelper", "./common/mobile/mobile-helper");
8484
$injector.require("devicePlatformsConstants", "./common/mobile/device-platforms-constants");
8585
$injector.require("htmlHelpService", "./common/services/html-help-service");
8686
$injector.requireCommand("dev-preuninstall", "./common/commands/preuninstall");
87+
$injector.requireCommand("doctor", "./common/commands/doctor");

commands/doctor.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
///<reference path="../../.d.ts"/>
2+
"use strict";
3+
4+
import os = require("os");
5+
import future = require("fibers/future");
6+
7+
export class DoctorCommand implements ICommand {
8+
9+
constructor(private $doctorService: IDoctorService,
10+
private $logger: ILogger) { }
11+
12+
public canExecute(args: string[]): IFuture<boolean> {
13+
return future.fromResult(true);
14+
}
15+
16+
public allowedParameters: ICommandParameter[] = [];
17+
18+
public execute(args: string[]): IFuture<void> {
19+
return (() => {
20+
var warningsPrinted = this.$doctorService.printWarnings();
21+
if (warningsPrinted) {
22+
this.$logger.out("Please note that these warnings are just used to help the NativeScript maintainers".bold + os.EOL +
23+
"with debugging if you file an issue. If everything you use NativeScript for is".bold + os.EOL +
24+
"working fine: please don't worry and just ignore them. Thanks!".bold);
25+
} else {
26+
this.$logger.out("No issues were detected.".bold);
27+
}
28+
}).future<void>()();
29+
}
30+
}
31+
32+
$injector.registerCommand("doctor", DoctorCommand);

commands/post-install.ts

+3-110
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ import os = require("os");
66
import helpers = require("../helpers");
77

88
export class PostInstallCommand implements ICommand {
9-
private static SEVEN_ZIP_ERROR_MESSAGE = "It looks like there's a problem with your system configuration. " +
10-
"You can find all system requirements on %s";
119

1210
constructor(private $fs: IFileSystem,
1311
private $staticConfig: Config.IStaticConfig,
1412
private $commandsService: ICommandsService,
1513
private $htmlHelpService: IHtmlHelpService,
16-
private $hostInfo: IHostInfo,
17-
private $sysInfo: ISysInfo,
18-
private $logger: ILogger,
19-
private $options: IOptions) {
14+
private $options: IOptions,
15+
private $doctorService: IDoctorService) {
2016
}
2117

2218
public disableAnalytics = true;
@@ -34,113 +30,10 @@ export class PostInstallCommand implements ICommand {
3430

3531
this.$htmlHelpService.generateHtmlPages().wait();
3632

37-
let sysInfo = this.$sysInfo.getSysInfo();
38-
let isNativeScript = this.$staticConfig.CLIENT_NAME === "tns";
39-
if (isNativeScript) {
40-
this.printNSWarnings(sysInfo);
41-
} else {
42-
this.printAppBuilderWarnings(sysInfo);
43-
}
33+
this.$doctorService.printWarnings();
4434

4535
this.$commandsService.tryExecuteCommand("autocomplete", []).wait();
4636
}).future<void>()();
4737
}
48-
49-
private printPackageManagerTip() {
50-
if (this.$hostInfo.isWindows) {
51-
this.$logger.out("TIP: To avoid setting up the necessary environment variables, you can use the chocolatey package manager to install the Android SDK and its dependencies." + os.EOL);
52-
} else if (this.$hostInfo.isDarwin) {
53-
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." + os.EOL);
54-
}
55-
}
56-
57-
private printNSWarnings(sysInfo: ISysInfoData) {
58-
if (!sysInfo.adbVer) {
59-
this.$logger.warn("WARNING: adb from the Android SDK is not installed or is not configured properly.");
60-
this.$logger.out("For Android-related operations, the NativeScript CLI will use a built-in version of adb." + os.EOL
61-
+ "To avoid possible issues with the native Android emulator, Genymotion or connected" + os.EOL
62-
+ "Android devices, verify that you have installed the latest Android SDK and" + os.EOL
63-
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + os.EOL);
64-
65-
this.printPackageManagerTip();
66-
}
67-
if (!sysInfo.antVer) {
68-
this.$logger.warn("WARNING: Apache Ant is not installed or is not configured properly.");
69-
this.$logger.out("You will not be able to build your projects for Android." + os.EOL
70-
+ "To be able to build for Android, download and install Apache Ant and" + os.EOL
71-
+ "its dependencies as described in http://ant.apache.org/manual/index.html" + os.EOL);
72-
73-
this.printPackageManagerTip();
74-
}
75-
if (!sysInfo.androidInstalled) {
76-
this.$logger.warn("WARNING: The Android SDK is not installed or is not configured properly.");
77-
this.$logger.out("You will not be able to build your projects for Android and run them in the native emulator." + os.EOL
78-
+ "To be able to build for Android and run apps in the native emulator, verify that you have" + os.EOL
79-
+ "installed the latest Android SDK and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + os.EOL
80-
);
81-
82-
this.printPackageManagerTip();
83-
}
84-
if (this.$hostInfo.isDarwin && !sysInfo.xcodeVer) {
85-
this.$logger.warn("WARNING: Xcode is not installed or is not configured properly.");
86-
this.$logger.out("You will not be able to build your projects for iOS or run them in the iOS Simulator." + os.EOL
87-
+ "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode." + os.EOL);
88-
}
89-
if (!sysInfo.itunesInstalled) {
90-
this.$logger.warn("WARNING: iTunes is not installed.");
91-
this.$logger.out("You will not be able to work with iOS devices via cable connection." + os.EOL
92-
+ "To be able to work with connected iOS devices," + os.EOL
93-
+ "download and install iTunes from http://www.apple.com" + os.EOL);
94-
}
95-
if(!sysInfo.javaVer) {
96-
this.$logger.warn("WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.");
97-
this.$logger.out("You will not be able to work with the Android SDK and you might not be able" + os.EOL
98-
+ "to perform some Android-related operations. To ensure that you can develop and" + os.EOL
99-
+ "test your apps for Android, verify that you have installed the JDK as" + os.EOL
100-
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)" + os.EOL
101-
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + os.EOL);
102-
}
103-
}
104-
105-
private printAppBuilderWarnings(sysInfo: ISysInfoData) {
106-
if (!sysInfo.adbVer) {
107-
this.$logger.warn("WARNING: adb from the Android SDK is not installed or is not configured properly. ");
108-
this.$logger.out("For Android-related operations, the AppBuilder CLI will use a built-in version of adb." + os.EOL
109-
+ "To avoid possible issues with the native Android emulator, Genymotion or connected" + os.EOL
110-
+ "Android devices, verify that you have installed the latest Android SDK and" + os.EOL
111-
+ "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + os.EOL);
112-
113-
this.printPackageManagerTip();
114-
}
115-
if (!sysInfo.androidInstalled) {
116-
this.$logger.warn("WARNING: The Android SDK is not installed or is not configured properly.");
117-
this.$logger.out("You will not be able to run your apps in the native emulator. To be able to run apps" + os.EOL
118-
+ "in the native Android emulator, verify that you have installed the latest Android SDK " + os.EOL
119-
+ "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements" + os.EOL
120-
);
121-
122-
this.printPackageManagerTip()
123-
}
124-
if (!sysInfo.itunesInstalled) {
125-
this.$logger.warn("WARNING: iTunes is not installed.");
126-
this.$logger.out("You will not be able to work with iOS devices via cable connection." + os.EOL
127-
+ "To be able to work with connected iOS devices," + os.EOL
128-
+ "download and install iTunes from http://www.apple.com" + os.EOL);
129-
}
130-
if(!sysInfo.javaVer) {
131-
this.$logger.warn("WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.");
132-
this.$logger.out("You will not be able to work with the Android SDK and you might not be able" + os.EOL
133-
+ "to perform some Android-related operations. To ensure that you can develop and" + os.EOL
134-
+ "test your apps for Android, verify that you have installed the JDK as" + os.EOL
135-
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)" + os.EOL
136-
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + os.EOL);
137-
}
138-
if(this.$hostInfo.isDarwin && (!sysInfo.monoVer || helpers.versionCompare(sysInfo.monoVer, "3.12.0") < 0)) {
139-
this.$logger.warn("WARNING: Mono 3.12 or later is not installed or not configured properly.");
140-
this.$logger.out("You will not be able to work with Android devices in the device simulator or debug on connected Android devices." + os.EOL
141-
+ "To be able to work with Android in the device simulator and debug on connected Android devices," + os.EOL
142-
+ "download and install Mono 3.12 or later from http://www.mono-project.com/download/" + os.EOL);
143-
}
144-
}
14538
}
14639
$injector.registerCommand("dev-post-install", PostInstallCommand);

0 commit comments

Comments
 (0)