Skip to content

Commit ab2e132

Browse files
author
Dimitar Kerezov
committed
Prompt for docs/setup-scripts upon doctor problems
If `$ tns doctor` detects any problems prompt the user to open docs and/or to run the setup script for his OS (if available). Default answers to both questions set to NO for NON-interactive consoles automation purposes. Default answers are set to YES for interactive consoles.
1 parent 04f6333 commit ab2e132

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/services/doctor-service.ts

+38
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
import {EOL} from "os";
44
import * as semver from "semver";
55
import * as path from "path";
6+
import * as helpers from "../common/helpers";
67
let clui = require("clui");
78

89
class DoctorService implements IDoctorService {
910
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
11+
private static DarwinSetupScriptLocation = path.join(__dirname, "..", "..", "setup", "mac-startup-shell-script.sh");
12+
private static DarwinSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-os-x";
13+
private static WindowsSetupScriptExecutable = "powershell.exe";
14+
private static WindowsSetupScriptArguments = ["start-process", "-FilePath", "PowerShell.exe", "-NoNewWindow", "-Wait", "-ArgumentList", '"-NoProfile -ExecutionPolicy Bypass -Command iex ((new-object net.webclient).DownloadString(\'https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.ps1\'))"'];
15+
private static WindowsSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-win";
16+
private static LinuxSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-linux";
1017

1118
constructor(private $analyticsService: IAnalyticsService,
1219
private $androidToolsInfo: IAndroidToolsInfo,
@@ -17,6 +24,8 @@ class DoctorService implements IDoctorService {
1724
private $childProcess: IChildProcess,
1825
private $config: IConfiguration,
1926
private $npm: INodePackageManager,
27+
private $opener: IOpener,
28+
private $prompter: IPrompter,
2029
private $fs: IFileSystem) { }
2130

2231
public printWarnings(configOptions?: { trackResult: boolean }): boolean {
@@ -95,9 +104,38 @@ class DoctorService implements IDoctorService {
95104
this.$analyticsService.track("DoctorEnvironmentSetup", doctorResult ? "incorrect" : "correct").wait();
96105
}
97106

107+
if(doctorResult) {
108+
this.$logger.info("There seem to be issues with your configuration.");
109+
if (this.$hostInfo.isDarwin) {
110+
this.promptForHelp(DoctorService.DarwinSetupDocsLink, DoctorService.DarwinSetupScriptLocation, []).wait();
111+
} else if (this.$hostInfo.isWindows) {
112+
this.promptForHelp(DoctorService.WindowsSetupDocsLink, DoctorService.WindowsSetupScriptExecutable, DoctorService.WindowsSetupScriptArguments).wait();
113+
} else {
114+
this.promptForDocs(DoctorService.LinuxSetupDocsLink).wait();
115+
}
116+
}
117+
98118
return doctorResult;
99119
}
100120

121+
private promptForDocs(link: string): IFuture<void> {
122+
return (() => {
123+
if (this.$prompter.confirm("Do you want to visit the official documentation?", () => helpers.isInteractive()).wait()) {
124+
this.$opener.open(link);
125+
}
126+
}).future<void>()();
127+
}
128+
129+
private promptForHelp(link: string, commandName: string, commandArguments: string[]): IFuture<void> {
130+
return (() => {
131+
this.promptForDocs(link).wait();
132+
133+
if (this.$prompter.confirm("Do you want to run the setup script?", () => helpers.isInteractive()).wait()) {
134+
this.$childProcess.spawnFromEvent(commandName, commandArguments, "close", { stdio: "inherit" }).wait();
135+
}
136+
}).future<void>()();
137+
}
138+
101139
private printPackageManagerTip() {
102140
if (this.$hostInfo.isWindows) {
103141
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." + EOL);

setup/mac-startup-shell-script.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.rb)"

0 commit comments

Comments
 (0)