@@ -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,8 +74,12 @@ export class CxInstaller {
74
74
await fs . promises . mkdir ( this . resourceDirPath , { recursive : true } ) ;
75
75
const cliVersion = await this . readASTCLIVersion ( ) ;
76
76
77
- if ( await this . checkLatestExecutableVersionIsInstalled ( ) ) {
78
- return ;
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
+ }
79
83
}
80
84
81
85
await this . cleanDirectoryContents ( this . resourceDirPath ) ;
@@ -98,27 +102,11 @@ export class CxInstaller {
98
102
fs . chmodSync ( this . getExecutablePath ( ) , 0o755 ) ;
99
103
logger . info ( 'Extracted CLI to:' , this . resourceDirPath ) ;
100
104
} catch ( error ) {
101
- if ( await this . checkLatestExecutableVersionIsInstalled ( ) ) {
102
- return ;
103
- }
104
105
logger . error ( 'Error during installation:' , error ) ;
105
106
process . exit ( 1 ) ;
106
107
}
107
108
}
108
109
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
-
122
110
private async cleanDirectoryContents ( directoryPath : string ) : Promise < void > {
123
111
try {
124
112
const files = await fsPromises . readdir ( directoryPath ) ;
@@ -208,7 +196,7 @@ export class CxInstaller {
208
196
private getCompressFolderName ( ) : string {
209
197
return `ast-cli.${ this . platform === winOS ? 'zip' : 'tar.gz' } ` ;
210
198
}
211
-
199
+
212
200
public getPlatform ( ) : SupportedPlatforms {
213
201
return this . platform ;
214
202
}
0 commit comments