33import { EOL } from "os" ;
44import * as semver from "semver" ;
55import * as path from "path" ;
6+ import * as helpers from "../common/helpers" ;
67let clui = require ( "clui" ) ;
78
89class 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 ) ;
0 commit comments