11import { EOL } from "os" ;
22import * as path from "path" ;
33import * as helpers from "../common/helpers" ;
4+ import { TrackActionNames } from "../constants" ;
45import { doctor , constants } from "nativescript-doctor" ;
56
67class DoctorService implements IDoctorService {
78 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" ;
99 private static WindowsSetupScriptExecutable = "powershell.exe" ;
1010 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" ;
1311
1412 constructor ( private $analyticsService : IAnalyticsService ,
1513 private $hostInfo : IHostInfo ,
1614 private $logger : ILogger ,
1715 private $childProcess : IChildProcess ,
18- private $opener : IOpener ,
19- private $prompter : IPrompter ,
16+ private $injector : IInjector ,
2017 private $terminalSpinnerService : ITerminalSpinnerService ,
2118 private $versionsService : IVersionsService ) { }
2219
@@ -41,7 +38,6 @@ class DoctorService implements IDoctorService {
4138
4239 if ( hasWarnings ) {
4340 this . $logger . info ( "There seem to be issues with your configuration." ) ;
44- await this . promptForHelp ( ) ;
4541 } else {
4642 this . $logger . out ( "No issues were detected." . bold ) ;
4743 }
@@ -51,61 +47,65 @@ class DoctorService implements IDoctorService {
5147 } catch ( err ) {
5248 this . $logger . error ( "Cannot get the latest versions information from npm. Please try again later." ) ;
5349 }
50+
51+ await this . $injector . resolve ( "platformEnvironmentRequirements" ) . checkEnvironmentRequirements ( null ) ;
5452 }
5553
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+
5760 if ( this . $hostInfo . isLinux ) {
61+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
62+ action : TrackActionNames . RunSetupScript ,
63+ additionalData : "Skipped as OS is Linux" ,
64+ } ) ;
5865 return ;
5966 }
6067
6168 this . $logger . out ( "Running the setup script to try and automatically configure your environment." ) ;
6269
6370 if ( this . $hostInfo . isDarwin ) {
64- return this . runSetupScriptCore ( DoctorService . DarwinSetupScriptLocation , [ ] ) ;
71+ await this . runSetupScriptCore ( DoctorService . DarwinSetupScriptLocation , [ ] ) ;
6572 }
6673
6774 if ( this . $hostInfo . isWindows ) {
68- return this . runSetupScriptCore ( DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
75+ await this . runSetupScriptCore ( DoctorService . WindowsSetupScriptExecutable , DoctorService . WindowsSetupScriptArguments ) ;
6976 }
77+
78+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
79+ action : TrackActionNames . RunSetupScript ,
80+ additionalData : "Finished" ,
81+ } ) ;
7082 }
7183
7284 public async canExecuteLocalBuild ( platform ?: string ) : Promise < boolean > {
85+ await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
86+ action : TrackActionNames . CheckLocalBuildSetup ,
87+ additionalData : "Starting" ,
88+ } ) ;
7389 const infos = await doctor . getInfos ( { platform } ) ;
7490
7591 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+ } ) ;
7798 this . printInfosCore ( infos ) ;
7899 } else {
79100 infos . map ( info => this . $logger . trace ( info . message ) ) ;
80101 }
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- }
95102
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+ } ) ;
105107
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 ;
109109 }
110110
111111 private async runSetupScriptCore ( executablePath : string , setupScriptArgs : string [ ] ) : Promise < ISpawnResult > {
0 commit comments