@@ -2,6 +2,7 @@ import { EOL } from "os";
2
2
import * as path from "path" ;
3
3
import * as helpers from "../common/helpers" ;
4
4
import { doctor , constants } from "nativescript-doctor" ;
5
+ // import { createTable } from "../common/helpers";
5
6
6
7
class DoctorService implements IDoctorService {
7
8
private static DarwinSetupScriptLocation = path . join ( __dirname , ".." , ".." , "setup" , "mac-startup-shell-script.sh" ) ;
@@ -17,10 +18,15 @@ class DoctorService implements IDoctorService {
17
18
private $childProcess : IChildProcess ,
18
19
private $opener : IOpener ,
19
20
private $prompter : IPrompter ,
21
+ private $terminalSpinnerService : ITerminalSpinnerService ,
20
22
private $versionsService : IVersionsService ) { }
21
23
22
24
public async printWarnings ( configOptions ?: { trackResult : boolean } ) : Promise < boolean > {
23
- const warnings = await doctor . getWarnings ( ) ;
25
+ const infos = await this . $terminalSpinnerService . execute < NativeScriptDoctor . IInfo [ ] > ( {
26
+ text : `Getting environment information ${ EOL } `
27
+ } , ( ) => doctor . getInfos ( ) ) ;
28
+
29
+ const warnings = infos . filter ( info => info . type === constants . WARNING_TYPE_NAME ) ;
24
30
const hasWarnings = warnings . length > 0 ;
25
31
26
32
const hasAndroidWarnings = warnings . filter ( warning => _ . includes ( warning . platforms , constants . ANDROID_PLATFORM_NAME ) ) . length > 0 ;
@@ -33,19 +39,9 @@ class DoctorService implements IDoctorService {
33
39
}
34
40
35
41
if ( hasWarnings ) {
36
- warnings . map ( warning => {
37
- this . $logger . warn ( warning . warning ) ;
38
- this . $logger . out ( warning . additionalInformation ) ;
39
- } ) ;
40
-
42
+ this . printInfosCore ( infos ) ;
41
43
this . $logger . info ( "There seem to be issues with your configuration." ) ;
42
- if ( this . $hostInfo . isDarwin ) {
43
- await this . promptForHelp ( DoctorService . DarwinSetupDocsLink , DoctorService . DarwinSetupScriptLocation , [ ] ) ;
44
- } else if ( this . $hostInfo . isWindows ) {
45
- await this . promptForHelp ( DoctorService . WindowsSetupDocsLink , DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
46
- } else {
47
- await this . promptForDocs ( DoctorService . LinuxSetupDocsLink ) ;
48
- }
44
+ await this . promptForHelp ( ) ;
49
45
}
50
46
51
47
try {
@@ -63,20 +59,54 @@ class DoctorService implements IDoctorService {
63
59
}
64
60
}
65
61
66
- private async promptForHelp ( link : string , commandName : string , commandArguments : string [ ] ) : Promise < void > {
62
+ private async promptForHelpCore ( link : string , commandName : string , commandArguments : string [ ] ) : Promise < void > {
67
63
await this . promptForDocs ( link ) ;
68
64
69
65
if ( await this . $prompter . confirm ( "Do you want to run the setup script?" , ( ) => helpers . isInteractive ( ) ) ) {
70
66
await this . $childProcess . spawnFromEvent ( commandName , commandArguments , "close" , { stdio : "inherit" } ) ;
71
67
}
72
68
}
73
69
70
+ private async promptForHelp ( ) : Promise < void > {
71
+ if ( this . $hostInfo . isDarwin ) {
72
+ await this . promptForHelpCore ( DoctorService . DarwinSetupDocsLink , DoctorService . DarwinSetupScriptLocation , [ ] ) ;
73
+ } else if ( this . $hostInfo . isWindows ) {
74
+ await this . promptForHelpCore ( DoctorService . WindowsSetupDocsLink , DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
75
+ } else {
76
+ await this . promptForDocs ( DoctorService . LinuxSetupDocsLink ) ;
77
+ }
78
+ }
79
+
74
80
private printPackageManagerTip ( ) {
75
81
if ( this . $hostInfo . isWindows ) {
76
82
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 ) ;
77
83
} else if ( this . $hostInfo . isDarwin ) {
78
84
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." + EOL ) ;
79
85
}
80
86
}
87
+
88
+ private printInfosCore ( infos : NativeScriptDoctor . IInfo [ ] ) : void {
89
+ infos . filter ( info => info . type === constants . WARNING_TYPE_NAME )
90
+ . map ( info => {
91
+ const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
92
+ spinner . text = `${ info . message . yellow } ${ EOL } ${ info . additionalInformation } ${ EOL } ` ;
93
+ spinner . fail ( ) ;
94
+ } ) ;
95
+
96
+ infos . filter ( info => info . type === constants . INFO_TYPE_NAME )
97
+ . map ( info => {
98
+ const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
99
+ spinner . text = info . message ;
100
+ spinner . succeed ( ) ;
101
+ } ) ;
102
+
103
+ // const table = createTable(["Index", "Message", "Additional Info"],
104
+ // infos.map((info, index) => {
105
+ // const message = info.type === constants.INFO_TYPE_NAME ? info.message.green : info.message.yellow;
106
+ // return [index.toString(), `${message.toString()} ${EOL}`, info.additionalInformation];
107
+ // })
108
+ // );
109
+ // console.log(table.toString());
110
+ }
81
111
}
82
112
$injector . register ( "doctorService" , DoctorService ) ;
0 commit comments