@@ -6,6 +6,7 @@ import axios from 'axios';
66import * as unzipper from 'unzipper' ;
77import { Semaphore } from 'async-mutex' ;
88import * as os from "os" ;
9+ import { logger } from "../wrapper/loggerConfig" ;
910
1011export class CxInstaller {
1112 private readonly platform : string ;
@@ -55,48 +56,42 @@ export class CxInstaller {
5556 }
5657
5758 async downloadIfNotInstalledCLI ( ) {
58- // Acquire the semaphore, ensuring only one installation happens at a time
5959 const [ _ , release ] = await CxInstaller . installSemaphore . acquire ( ) ;
6060 try {
6161 if ( this . checkExecutableExists ( ) ) {
62- console . log ( 'Executable already installed.' ) ;
62+ logger . info ( 'Executable already installed.' ) ;
6363 return ;
6464 }
6565
6666 const url = await this . getDownloadURL ( ) ;
6767 const zipPath = path . join ( os . tmpdir ( ) , `ast-cli.${ this . platform === 'win32' ? 'zip' : 'tar.gz' } ` ) ;
6868
6969 await this . downloadFile ( url , zipPath ) ;
70- console . log ( 'Downloaded CLI to:' , zipPath ) ;
70+ logger . info ( 'Downloaded CLI to:' , zipPath ) ;
7171
7272 await this . extractArchive ( zipPath , this . resourceDirPath ) ;
7373 fs1 . chmodSync ( this . getExecutablePath ( ) , 0o777 ) ;
74- console . log ( 'Extracted CLI to:' , this . resourceDirPath ) ;
74+ logger . info ( 'Extracted CLI to:' , this . resourceDirPath ) ;
7575 } catch ( error ) {
76- console . error ( 'Error during installation:' , error ) ;
76+ logger . error ( 'Error during installation:' , error ) ;
7777 } finally {
78- // Release the semaphore lock to allow the next waiting process to continue
79- release ( ) ; // Call the release function
78+ release ( ) ;
8079 }
8180 }
8281
8382 async extractArchive ( zipPath : string , extractPath : string ) : Promise < void > {
8483 if ( zipPath . endsWith ( '.zip' ) ) {
85- console . log ( 'Extracting ZIP file...' ) ;
8684 await unzipper . Open . file ( zipPath )
8785 . then ( d => d . extract ( { path : extractPath } ) ) ;
88- console . log ( 'Extracted ZIP file to:' , extractPath ) ;
8986 } else if ( zipPath . endsWith ( '.tar.gz' ) ) {
90- console . log ( 'Extracting TAR.GZ file...' ) ;
9187 await tar . extract ( { file : zipPath , cwd : extractPath } ) ;
92- console . log ( 'Extracted TAR.GZ file to:' , extractPath ) ;
9388 } 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.' ) ;
9590 }
9691 }
9792
9893 async downloadFile ( url : string , outputPath : string ) {
99- console . log ( 'Downloading file from:' , url ) ;
94+ logger . info ( 'Downloading file from:' , url ) ;
10095 const writer = fs1 . createWriteStream ( outputPath ) ;
10196 const response = await axios ( { url, responseType : 'stream' } ) ;
10297 response . data . pipe ( writer ) ;
@@ -120,7 +115,7 @@ export class CxInstaller {
120115 const versionContent = await fs . readFile ( versionFilePath , 'utf-8' ) ;
121116 return versionContent . trim ( ) ;
122117 } catch ( error ) {
123- throw new Error ( 'Error reading AST CLI version: ' + error . message ) ;
118+ logger . error ( 'Error reading AST CLI version: ' + error . message ) ;
124119 }
125120 }
126121}
0 commit comments