3
3
import { EOL } from "os" ;
4
4
import * as semver from "semver" ;
5
5
import * as path from "path" ;
6
+ import * as helpers from "../common/helpers" ;
6
7
let clui = require ( "clui" ) ;
7
8
8
9
class DoctorService implements IDoctorService {
9
10
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" ;
10
17
11
18
constructor ( private $analyticsService : IAnalyticsService ,
12
19
private $androidToolsInfo : IAndroidToolsInfo ,
@@ -17,6 +24,8 @@ class DoctorService implements IDoctorService {
17
24
private $childProcess : IChildProcess ,
18
25
private $config : IConfiguration ,
19
26
private $npm : INodePackageManager ,
27
+ private $opener : IOpener ,
28
+ private $prompter : IPrompter ,
20
29
private $fs : IFileSystem ) { }
21
30
22
31
public printWarnings ( configOptions ?: { trackResult : boolean } ) : boolean {
@@ -95,9 +104,38 @@ class DoctorService implements IDoctorService {
95
104
this . $analyticsService . track ( "DoctorEnvironmentSetup" , doctorResult ? "incorrect" : "correct" ) . wait ( ) ;
96
105
}
97
106
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
+
98
118
return doctorResult ;
99
119
}
100
120
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
+
101
139
private printPackageManagerTip ( ) {
102
140
if ( this . $hostInfo . isWindows ) {
103
141
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