1
1
import { EOL } from "os" ;
2
2
import * as path from "path" ;
3
3
import * as helpers from "../common/helpers" ;
4
+ import { TrackActionNames } from "../constants" ;
4
5
import { doctor , constants } from "nativescript-doctor" ;
5
6
6
7
class DoctorService implements IDoctorService {
7
8
private static DarwinSetupScriptLocation = path . join ( __dirname , ".." , ".." , "setup" , "mac-startup-shell-script.sh" ) ;
8
- private static DarwinSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-os-x" ;
9
9
private static WindowsSetupScriptExecutable = "powershell.exe" ;
10
10
private static WindowsSetupScriptArguments = [ "start-process" , "-FilePath" , "PowerShell.exe" , "-NoNewWindow" , "-Wait" , "-ArgumentList" , '"-NoProfile -ExecutionPolicy Bypass -Command iex ((new-object net.webclient).DownloadString(\'https://www.nativescript.org/setup/win\'))"' ] ;
11
- private static WindowsSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-win" ;
12
- private static LinuxSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-linux" ;
13
11
14
12
constructor ( private $analyticsService : IAnalyticsService ,
15
13
private $hostInfo : IHostInfo ,
16
14
private $logger : ILogger ,
17
15
private $childProcess : IChildProcess ,
18
- private $opener : IOpener ,
19
- private $prompter : IPrompter ,
16
+ private $injector : IInjector ,
20
17
private $terminalSpinnerService : ITerminalSpinnerService ,
21
18
private $versionsService : IVersionsService ) { }
22
19
@@ -41,7 +38,6 @@ class DoctorService implements IDoctorService {
41
38
42
39
if ( hasWarnings ) {
43
40
this . $logger . info ( "There seem to be issues with your configuration." ) ;
44
- await this . promptForHelp ( ) ;
45
41
} else {
46
42
this . $logger . out ( "No issues were detected." . bold ) ;
47
43
}
@@ -51,61 +47,65 @@ class DoctorService implements IDoctorService {
51
47
} catch ( err ) {
52
48
this . $logger . error ( "Cannot get the latest versions information from npm. Please try again later." ) ;
53
49
}
50
+
51
+ await this . $injector . resolve ( "platformEnvironmentRequirements" ) . checkEnvironmentRequirements ( null ) ;
54
52
}
55
53
56
- public runSetupScript ( ) : Promise < ISpawnResult > {
54
+ public async runSetupScript ( ) : Promise < ISpawnResult > {
55
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
56
+ action : TrackActionNames . RunSetupScript ,
57
+ additionalData : "Starting" ,
58
+ } ) ;
59
+
57
60
if ( this . $hostInfo . isLinux ) {
61
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
62
+ action : TrackActionNames . RunSetupScript ,
63
+ additionalData : "Skipped as OS is Linux" ,
64
+ } ) ;
58
65
return ;
59
66
}
60
67
61
68
this . $logger . out ( "Running the setup script to try and automatically configure your environment." ) ;
62
69
63
70
if ( this . $hostInfo . isDarwin ) {
64
- return this . runSetupScriptCore ( DoctorService . DarwinSetupScriptLocation , [ ] ) ;
71
+ await this . runSetupScriptCore ( DoctorService . DarwinSetupScriptLocation , [ ] ) ;
65
72
}
66
73
67
74
if ( this . $hostInfo . isWindows ) {
68
- return this . runSetupScriptCore ( DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
75
+ await this . runSetupScriptCore ( DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
69
76
}
77
+
78
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
79
+ action : TrackActionNames . RunSetupScript ,
80
+ additionalData : "Finished" ,
81
+ } ) ;
70
82
}
71
83
72
84
public async canExecuteLocalBuild ( platform ?: string ) : Promise < boolean > {
85
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
86
+ action : TrackActionNames . CheckLocalBuildSetup ,
87
+ additionalData : "Starting" ,
88
+ } ) ;
73
89
const infos = await doctor . getInfos ( { platform } ) ;
74
90
75
91
const warnings = this . filterInfosByType ( infos , constants . WARNING_TYPE_NAME ) ;
76
- if ( warnings . length > 0 ) {
92
+ const hasWarnings = warnings . length > 0 ;
93
+ if ( hasWarnings ) {
94
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
95
+ action : TrackActionNames . CheckLocalBuildSetup ,
96
+ additionalData : `Warnings:${ warnings . map ( w => w . message ) . join ( "__" ) } ` ,
97
+ } ) ;
77
98
this . printInfosCore ( infos ) ;
78
99
} else {
79
100
infos . map ( info => this . $logger . trace ( info . message ) ) ;
80
101
}
81
- return warnings . length === 0 ;
82
- }
83
-
84
- private async promptForDocs ( link : string ) : Promise < void > {
85
- if ( await this . $prompter . confirm ( "Do you want to visit the official documentation?" , ( ) => helpers . isInteractive ( ) ) ) {
86
- this . $opener . open ( link ) ;
87
- }
88
- }
89
-
90
- private async promptForSetupScript ( executablePath : string , setupScriptArgs : string [ ] ) : Promise < void > {
91
- if ( await this . $prompter . confirm ( "Do you want to run the setup script?" , ( ) => helpers . isInteractive ( ) ) ) {
92
- await this . runSetupScriptCore ( executablePath , setupScriptArgs ) ;
93
- }
94
- }
95
102
96
- private async promptForHelp ( ) : Promise < void > {
97
- if ( this . $hostInfo . isDarwin ) {
98
- await this . promptForHelpCore ( DoctorService . DarwinSetupDocsLink , DoctorService . DarwinSetupScriptLocation , [ ] ) ;
99
- } else if ( this . $hostInfo . isWindows ) {
100
- await this . promptForHelpCore ( DoctorService . WindowsSetupDocsLink , DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
101
- } else {
102
- await this . promptForDocs ( DoctorService . LinuxSetupDocsLink ) ;
103
- }
104
- }
103
+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
104
+ action : TrackActionNames . CheckLocalBuildSetup ,
105
+ additionalData : `Finished: Is setup correct: ${ ! hasWarnings } ` ,
106
+ } ) ;
105
107
106
- private async promptForHelpCore ( link : string , setupScriptExecutablePath : string , setupScriptArgs : string [ ] ) : Promise < void > {
107
- await this . promptForDocs ( link ) ;
108
- await this . promptForSetupScript ( setupScriptExecutablePath , setupScriptArgs ) ;
108
+ return ! hasWarnings ;
109
109
}
110
110
111
111
private async runSetupScriptCore ( executablePath : string , setupScriptArgs : string [ ] ) : Promise < ISpawnResult > {
0 commit comments