@@ -10,18 +10,18 @@ const arch = os.arch();
1010// Determine which binary to download
1111let binaryName ;
1212if ( platform === 'win32' ) {
13- binaryName = arch === 'x64' ? 'term-rex-windows-amd64.exe ' : 'term-rex-windows-arm64.exe' ;
13+ binaryName = arch === 'x64' ? 'term-rex_0.1.2_windows_amd64.zip ' : null ;
1414} else if ( platform === 'darwin' ) {
15- binaryName = arch === 'x64' ? 'term-rex-macos-amd64 ' : 'term-rex-macos-arm64 ' ;
15+ binaryName = arch === 'x64' ? 'term-rex_0.1.2_darwin_amd64.tar.gz ' : 'term-rex_0.1.2_darwin_arm64.tar.gz ' ;
1616} else if ( platform === 'linux' ) {
17- binaryName = arch === 'x64' ? 'term-rex-linux-amd64 ' : 'term-rex-linux-arm64 ' ;
17+ binaryName = arch === 'x64' ? 'term-rex_0.1.2_linux_amd64.tar.gz ' : 'term-rex_0.1.2_linux_arm64.tar.gz ' ;
1818} else {
1919 console . error ( 'Unsupported platform:' , platform ) ;
2020 process . exit ( 1 ) ;
2121}
2222
2323// Download URL (assuming binaries are uploaded to GitHub Releases)
24- const downloadUrl = `https://github.com/jianongHe/Term-Rex/releases/download/v1.0.0 /${ binaryName } ` ;
24+ const downloadUrl = `https://github.com/jianongHe/Term-Rex/releases/download/v0.1.2 /${ binaryName } ` ;
2525
2626// Local binary path
2727const binPath = path . join ( __dirname , 'bin' ) ;
@@ -34,20 +34,66 @@ if (!fs.existsSync(binPath)) {
3434
3535// Download binary file
3636console . log ( `Downloading ${ binaryName } ...` ) ;
37- const file = fs . createWriteStream ( binaryPath ) ;
37+
38+ // Create a temporary directory for extraction
39+ const tempDir = path . join ( os . tmpdir ( ) , `term-rex-${ Math . random ( ) . toString ( 36 ) . substring ( 7 ) } ` ) ;
40+ fs . mkdirSync ( tempDir , { recursive : true } ) ;
41+
42+ const tempFile = path . join ( tempDir , binaryName ) ;
43+ const file = fs . createWriteStream ( tempFile ) ;
44+
3845https . get ( downloadUrl , ( response ) => {
3946 response . pipe ( file ) ;
4047 file . on ( 'finish' , ( ) => {
4148 file . close ( ( ) => {
4249 console . log ( 'Download complete' ) ;
43- // Set execute permissions
44- if ( platform !== 'win32' ) {
45- fs . chmodSync ( binaryPath , '755' ) ;
50+
51+ // Extract the archive
52+ console . log ( 'Extracting...' ) ;
53+ if ( binaryName . endsWith ( '.zip' ) ) {
54+ // For Windows, we need to extract the zip file
55+ const extract = require ( 'extract-zip' ) ;
56+ extract ( tempFile , { dir : tempDir } )
57+ . then ( ( ) => {
58+ // Find the executable in the extracted files
59+ const files = fs . readdirSync ( tempDir ) ;
60+ const exeFile = files . find ( f => f . endsWith ( '.exe' ) ) ;
61+ if ( ! exeFile ) {
62+ throw new Error ( 'Could not find executable in zip file' ) ;
63+ }
64+
65+ // Copy to bin directory
66+ fs . copyFileSync ( path . join ( tempDir , exeFile ) , binaryPath ) ;
67+ console . log ( 'Installation complete! You can now run the game using the term-rex command.' ) ;
68+ } )
69+ . catch ( err => {
70+ console . error ( 'Extraction failed:' , err . message ) ;
71+ } ) ;
72+ } else {
73+ // For Unix systems, extract the tar.gz file
74+ const tar = require ( 'tar' ) ;
75+ tar . extract ( {
76+ file : tempFile ,
77+ cwd : tempDir
78+ } ) . then ( ( ) => {
79+ // Find the executable in the extracted files
80+ const files = fs . readdirSync ( tempDir ) ;
81+ const exeFile = files . find ( f => f === 'term-rex' ) ;
82+ if ( ! exeFile ) {
83+ throw new Error ( 'Could not find executable in tar.gz file' ) ;
84+ }
85+
86+ // Copy to bin directory
87+ fs . copyFileSync ( path . join ( tempDir , exeFile ) , binaryPath ) ;
88+ fs . chmodSync ( binaryPath , '755' ) ;
89+ console . log ( 'Installation complete! You can now run the game using the term-rex command.' ) ;
90+ } ) . catch ( err => {
91+ console . error ( 'Extraction failed:' , err . message ) ;
92+ } ) ;
4693 }
47- console . log ( 'Installation complete! You can now run the game using the term-rex command.' ) ;
4894 } ) ;
4995 } ) ;
5096} ) . on ( 'error' , ( err ) => {
51- fs . unlink ( binaryPath ) ;
97+ fs . unlink ( tempFile , ( ) => { } ) ;
5298 console . error ( 'Download failed:' , err . message ) ;
5399} ) ;
0 commit comments