@@ -9,6 +9,11 @@ export class DoctorService implements IDoctorService {
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
11
12
+ private get $jsonFileSettingsService ( ) : IJsonFileSettingsService {
13
+ const jsonFileSettingsPath = path . join ( this . $settingsService . getProfileDir ( ) , "doctor-cache.json" ) ;
14
+ return this . $injector . resolve < IJsonFileSettingsService > ( "jsonFileSettingsService" , { jsonFileSettingsPath } ) ;
15
+ }
16
+
12
17
constructor ( private $analyticsService : IAnalyticsService ,
13
18
private $hostInfo : IHostInfo ,
14
19
private $logger : ILogger ,
@@ -17,12 +22,14 @@ export class DoctorService implements IDoctorService {
17
22
private $projectDataService : IProjectDataService ,
18
23
private $fs : IFileSystem ,
19
24
private $terminalSpinnerService : ITerminalSpinnerService ,
20
- private $versionsService : IVersionsService ) { }
25
+ private $versionsService : IVersionsService ,
26
+ private $settingsService : ISettingsService ) { }
21
27
22
28
public async printWarnings ( configOptions ?: { trackResult : boolean , projectDir ?: string , runtimeVersion ?: string , options ?: IOptions } ) : Promise < void > {
29
+ const getInfosData : any = { projectDir : configOptions && configOptions . projectDir , androidRuntimeVersion : configOptions && configOptions . runtimeVersion } ;
23
30
const infos = await this . $terminalSpinnerService . execute < NativeScriptDoctor . IInfo [ ] > ( {
24
31
text : `Getting environment information ${ EOL } `
25
- } , ( ) => doctor . getInfos ( { projectDir : configOptions && configOptions . projectDir , androidRuntimeVersion : configOptions && configOptions . runtimeVersion } ) ) ;
32
+ } , ( ) => this . getInfos ( getInfosData ) ) ;
26
33
27
34
const warnings = infos . filter ( info => info . type === constants . WARNING_TYPE_NAME ) ;
28
35
const hasWarnings = warnings . length > 0 ;
@@ -41,6 +48,7 @@ export class DoctorService implements IDoctorService {
41
48
this . $logger . info ( "There seem to be issues with your configuration." ) ;
42
49
} else {
43
50
this . $logger . info ( "No issues were detected." . bold ) ;
51
+ await this . $jsonFileSettingsService . saveSetting ( this . getKeyForConfiguration ( getInfosData ) , infos ) ;
44
52
this . printInfosCore ( infos ) ;
45
53
}
46
54
@@ -95,8 +103,8 @@ export class DoctorService implements IDoctorService {
95
103
action : TrackActionNames . CheckLocalBuildSetup ,
96
104
additionalData : "Starting" ,
97
105
} ) ;
98
- const infos = await doctor . getInfos ( { platform, projectDir, androidRuntimeVersion : runtimeVersion } ) ;
99
-
106
+ const sysInfoConfig : NativeScriptDoctor . ISysInfoConfig = { platform, projectDir, androidRuntimeVersion : runtimeVersion } ;
107
+ const infos = await this . getInfos ( sysInfoConfig ) ;
100
108
const warnings = this . filterInfosByType ( infos , constants . WARNING_TYPE_NAME ) ;
101
109
const hasWarnings = warnings . length > 0 ;
102
110
if ( hasWarnings ) {
@@ -107,6 +115,7 @@ export class DoctorService implements IDoctorService {
107
115
this . printInfosCore ( infos ) ;
108
116
} else {
109
117
infos . map ( info => this . $logger . trace ( info . message ) ) ;
118
+ await this . $jsonFileSettingsService . saveSetting ( this . getKeyForConfiguration ( sysInfoConfig ) , infos ) ;
110
119
}
111
120
112
121
await this . $analyticsService . trackEventActionInGoogleAnalytics ( {
@@ -221,5 +230,35 @@ export class DoctorService implements IDoctorService {
221
230
private filterInfosByType ( infos : NativeScriptDoctor . IInfo [ ] , type : string ) : NativeScriptDoctor . IInfo [ ] {
222
231
return infos . filter ( info => info . type === type ) ;
223
232
}
233
+
234
+ private getKeyForConfiguration ( sysInfoConfig ?: NativeScriptDoctor . ISysInfoConfig ) : string {
235
+ const nativeScriptData = sysInfoConfig && sysInfoConfig . projectDir && JSON . stringify ( this . $fs . readJson ( path . join ( sysInfoConfig . projectDir , "package.json" ) ) . nativescript ) ;
236
+ const delimiter = "__" ;
237
+ const key = [
238
+ JSON . stringify ( sysInfoConfig ) ,
239
+ process . env . ANDROID_HOME ,
240
+ process . env . JAVA_HOME ,
241
+ process . env [ "CommonProgramFiles(x86)" ] ,
242
+ process . env [ "CommonProgramFiles" ] ,
243
+ process . env . PROCESSOR_ARCHITEW6432 ,
244
+ process . env . ProgramFiles ,
245
+ process . env [ "ProgramFiles(x86)" ] ,
246
+ nativeScriptData
247
+ ]
248
+ . filter ( a => ! ! a )
249
+ . join ( delimiter ) ;
250
+
251
+ const data = helpers . getHash ( key , { algorithm : "md5" } ) ;
252
+ return data ;
253
+ }
254
+
255
+ private async getInfos ( sysInfoConfig ?: NativeScriptDoctor . ISysInfoConfig ) : Promise < NativeScriptDoctor . IInfo [ ] > {
256
+ const key = this . getKeyForConfiguration ( sysInfoConfig ) ;
257
+ // check if we already have cache for the results here
258
+ const infosFromCache = await this . $jsonFileSettingsService . getSettingValue < NativeScriptDoctor . IInfo [ ] > ( key ) ;
259
+ const infos = infosFromCache || await doctor . getInfos ( sysInfoConfig ) ;
260
+
261
+ return infos ;
262
+ }
224
263
}
225
264
$injector . register ( "doctorService" , DoctorService ) ;
0 commit comments