@@ -25,9 +25,9 @@ export class CxInstaller {
2525 private readonly client : AstClient ;
2626
2727 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' }
3131 } ;
3232
3333 constructor ( platform : string , client : AstClient ) {
@@ -74,12 +74,8 @@ export class CxInstaller {
7474 await fs . promises . mkdir ( this . resourceDirPath , { recursive : true } ) ;
7575 const cliVersion = await this . readASTCLIVersion ( ) ;
7676
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 ;
8379 }
8480
8581 await this . cleanDirectoryContents ( this . resourceDirPath ) ;
@@ -102,11 +98,27 @@ export class CxInstaller {
10298 fs . chmodSync ( this . getExecutablePath ( ) , 0o755 ) ;
10399 logger . info ( 'Extracted CLI to:' , this . resourceDirPath ) ;
104100 } catch ( error ) {
101+ if ( await this . checkLatestExecutableVersionIsInstalled ( ) ) {
102+ return ;
103+ }
105104 logger . error ( 'Error during installation:' , error ) ;
106105 process . exit ( 1 ) ;
107106 }
108107 }
109108
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+
110122 private async cleanDirectoryContents ( directoryPath : string ) : Promise < void > {
111123 try {
112124 const files = await fsPromises . readdir ( directoryPath ) ;
@@ -196,7 +208,7 @@ export class CxInstaller {
196208 private getCompressFolderName ( ) : string {
197209 return `ast-cli.${ this . platform === winOS ? 'zip' : 'tar.gz' } ` ;
198210 }
199-
211+
200212 public getPlatform ( ) : SupportedPlatforms {
201213 return this . platform ;
202214 }
0 commit comments