@@ -25,9 +25,9 @@ export class CxInstaller {
25
25
private readonly client : AstClient ;
26
26
27
27
private static readonly PLATFORMS : Record < SupportedPlatforms , PlatformData > = {
28
- win32 : { platform : 'windows' , extension : 'zip' } ,
29
- darwin : { platform : macOS , extension : 'tar.gz' } ,
30
- linux : { platform : linuxOS , extension : 'tar.gz' }
28
+ win32 : { platform : 'windows' , extension : 'zip' } ,
29
+ darwin : { platform : macOS , extension : 'tar.gz' } ,
30
+ linux : { platform : linuxOS , extension : 'tar.gz' }
31
31
} ;
32
32
33
33
constructor ( platform : string , client : AstClient ) {
@@ -74,12 +74,8 @@ export class CxInstaller {
74
74
await fs . promises . mkdir ( this . resourceDirPath , { recursive : true } ) ;
75
75
const cliVersion = await this . readASTCLIVersion ( ) ;
76
76
77
- if ( this . checkExecutableExists ( ) ) {
78
- const installedVersion = await this . readInstalledVersionFile ( this . resourceDirPath ) ;
79
- if ( installedVersion === cliVersion ) {
80
- logger . info ( 'Executable already installed.' ) ;
81
- return ;
82
- }
77
+ if ( await this . checkLatestExecutableVersionIsInstalled ( ) ) {
78
+ return ;
83
79
}
84
80
85
81
await this . cleanDirectoryContents ( this . resourceDirPath ) ;
@@ -102,11 +98,27 @@ export class CxInstaller {
102
98
fs . chmodSync ( this . getExecutablePath ( ) , 0o755 ) ;
103
99
logger . info ( 'Extracted CLI to:' , this . resourceDirPath ) ;
104
100
} catch ( error ) {
101
+ if ( await this . checkLatestExecutableVersionIsInstalled ( ) ) {
102
+ return ;
103
+ }
105
104
logger . error ( 'Error during installation:' , error ) ;
106
105
process . exit ( 1 ) ;
107
106
}
108
107
}
109
108
109
+ private async checkLatestExecutableVersionIsInstalled ( ) : Promise < boolean > {
110
+ const cliVersion = await this . readASTCLIVersion ( ) ;
111
+
112
+ if ( this . checkExecutableExists ( ) ) {
113
+ const installedVersion = await this . readInstalledVersionFile ( this . resourceDirPath ) ;
114
+ if ( installedVersion === cliVersion ) {
115
+ logger . info ( 'Executable already installed.' ) ;
116
+ return true ;
117
+ }
118
+ }
119
+ return false ;
120
+ }
121
+
110
122
private async cleanDirectoryContents ( directoryPath : string ) : Promise < void > {
111
123
try {
112
124
const files = await fsPromises . readdir ( directoryPath ) ;
@@ -196,7 +208,7 @@ export class CxInstaller {
196
208
private getCompressFolderName ( ) : string {
197
209
return `ast-cli.${ this . platform === winOS ? 'zip' : 'tar.gz' } ` ;
198
210
}
199
-
211
+
200
212
public getPlatform ( ) : SupportedPlatforms {
201
213
return this . platform ;
202
214
}
0 commit comments