@@ -60,25 +60,33 @@ const buildDownloadBinaryUrl = (version) => {
6060}
6161
6262async function installBinary ( ) {
63- const packageVersion = require ( './package.json' ) . version ;
64- const cliVersion = getExpectedCliVersion
63+ const cliVersion = getExpectedCliVersion ( ) ;
64+ if ( fs . existsSync ( binaryPath ) ) {
65+ console . log ( 'Removing existing binary...' ) ;
66+ fs . unlinkSync ( binaryPath ) ;
67+ }
6568 const downloadUrl = buildDownloadBinaryUrl ( cliVersion ) ;
6669 if ( ! fs . existsSync ( path . join ( __dirname , 'bin' ) ) ) {
6770 fs . mkdirSync ( path . join ( __dirname , 'bin' ) ) ;
6871 }
6972
70- const response = await axios ( {
71- url : downloadUrl ,
72- method : 'GET' ,
73- responseType : 'stream'
74- } ) ;
75-
76- const writer = fs . createWriteStream ( binaryPath ) ;
77- response . data . pipe ( writer ) ;
78- await new Promise ( ( resolve , reject ) => {
79- writer . on ( 'finish' , resolve ) ;
80- writer . on ( 'error' , reject ) ;
81- } ) ;
73+ try {
74+ const response = await axios ( {
75+ url : downloadUrl ,
76+ method : 'GET' ,
77+ responseType : 'stream'
78+ } ) ;
79+
80+ const writer = fs . createWriteStream ( binaryPath ) ;
81+ response . data . pipe ( writer ) ;
82+ await new Promise ( ( resolve , reject ) => {
83+ writer . on ( 'finish' , resolve ) ;
84+ writer . on ( 'error' , reject ) ;
85+ } ) ;
86+ } catch ( error ) {
87+ console . error ( 'Error downloading SimpleLocalize CLI binary:' , error . message ) ;
88+ process . exit ( 1 ) ;
89+ }
8290
8391 // Make it executable (only on Unix-based systems)
8492 if ( os . platform ( ) !== 'win32' ) {
@@ -94,7 +102,7 @@ async function installBinary() {
94102
95103const linkToNodeModulesBin = ( ) => {
96104 let nodeModulesBinPath = path . join ( __dirname , '..' , '..' , '.bin' , 'simplelocalize' ) ;
97-
105+
98106 if ( os . platform ( ) === 'win32' ) {
99107 nodeModulesBinPath += '.exe' ;
100108 }
0 commit comments