@@ -6,6 +6,7 @@ import axios from 'axios';
6
6
import * as unzipper from 'unzipper' ;
7
7
import { Semaphore } from 'async-mutex' ;
8
8
import * as os from "os" ;
9
+ import { logger } from "../wrapper/loggerConfig" ;
9
10
10
11
export class CxInstaller {
11
12
private readonly platform : string ;
@@ -55,48 +56,42 @@ export class CxInstaller {
55
56
}
56
57
57
58
async downloadIfNotInstalledCLI ( ) {
58
- // Acquire the semaphore, ensuring only one installation happens at a time
59
59
const [ _ , release ] = await CxInstaller . installSemaphore . acquire ( ) ;
60
60
try {
61
61
if ( this . checkExecutableExists ( ) ) {
62
- console . log ( 'Executable already installed.' ) ;
62
+ logger . info ( 'Executable already installed.' ) ;
63
63
return ;
64
64
}
65
65
66
66
const url = await this . getDownloadURL ( ) ;
67
67
const zipPath = path . join ( os . tmpdir ( ) , `ast-cli.${ this . platform === 'win32' ? 'zip' : 'tar.gz' } ` ) ;
68
68
69
69
await this . downloadFile ( url , zipPath ) ;
70
- console . log ( 'Downloaded CLI to:' , zipPath ) ;
70
+ logger . info ( 'Downloaded CLI to:' , zipPath ) ;
71
71
72
72
await this . extractArchive ( zipPath , this . resourceDirPath ) ;
73
73
fs1 . chmodSync ( this . getExecutablePath ( ) , 0o777 ) ;
74
- console . log ( 'Extracted CLI to:' , this . resourceDirPath ) ;
74
+ logger . info ( 'Extracted CLI to:' , this . resourceDirPath ) ;
75
75
} catch ( error ) {
76
- console . error ( 'Error during installation:' , error ) ;
76
+ logger . error ( 'Error during installation:' , error ) ;
77
77
} finally {
78
- // Release the semaphore lock to allow the next waiting process to continue
79
- release ( ) ; // Call the release function
78
+ release ( ) ;
80
79
}
81
80
}
82
81
83
82
async extractArchive ( zipPath : string , extractPath : string ) : Promise < void > {
84
83
if ( zipPath . endsWith ( '.zip' ) ) {
85
- console . log ( 'Extracting ZIP file...' ) ;
86
84
await unzipper . Open . file ( zipPath )
87
85
. then ( d => d . extract ( { path : extractPath } ) ) ;
88
- console . log ( 'Extracted ZIP file to:' , extractPath ) ;
89
86
} else if ( zipPath . endsWith ( '.tar.gz' ) ) {
90
- console . log ( 'Extracting TAR.GZ file...' ) ;
91
87
await tar . extract ( { file : zipPath , cwd : extractPath } ) ;
92
- console . log ( 'Extracted TAR.GZ file to:' , extractPath ) ;
93
88
} else {
94
- console . error ( 'Unsupported file type. Only .zip and .tar.gz are supported.' ) ;
89
+ logger . error ( 'Unsupported file type. Only .zip and .tar.gz are supported.' ) ;
95
90
}
96
91
}
97
92
98
93
async downloadFile ( url : string , outputPath : string ) {
99
- console . log ( 'Downloading file from:' , url ) ;
94
+ logger . info ( 'Downloading file from:' , url ) ;
100
95
const writer = fs1 . createWriteStream ( outputPath ) ;
101
96
const response = await axios ( { url, responseType : 'stream' } ) ;
102
97
response . data . pipe ( writer ) ;
@@ -120,7 +115,7 @@ export class CxInstaller {
120
115
const versionContent = await fs . readFile ( versionFilePath , 'utf-8' ) ;
121
116
return versionContent . trim ( ) ;
122
117
} catch ( error ) {
123
- throw new Error ( 'Error reading AST CLI version: ' + error . message ) ;
118
+ logger . error ( 'Error reading AST CLI version: ' + error . message ) ;
124
119
}
125
120
}
126
121
}
0 commit comments