@@ -5,8 +5,10 @@ const path = require("path");
55const os = require ( "os" ) ;
66const https = require ( "https" ) ;
77
8- const downloadDir = "../.bin/" ;
9- const downloadFrom = "https://github.com/NpgsqlRest/NpgsqlRest/releases/download/v3.7.0/" ;
8+ const downloadFrom = "https://github.com/NpgsqlRest/NpgsqlRest/releases/download/v3.8.0/" ;
9+
10+ // Download binary next to this script, not to ../.bin/
11+ const binDir = path . join ( __dirname , "bin" ) ;
1012
1113function download ( url , to , done ) {
1214 https . get ( url , ( response ) => {
@@ -15,13 +17,13 @@ function download(url, to, done) {
1517 response . pipe ( file ) ;
1618 file . on ( "finish" , ( ) => {
1719 file . close ( ) ;
18- console . info ( `${ to } ...` , ) ;
20+ console . info ( `Downloaded ${ path . basename ( to ) } ` ) ;
1921 if ( done ) {
2022 done ( ) ;
2123 }
2224 } ) ;
2325 } else if ( response . statusCode == 302 ) {
24- download ( response . headers . location , to ) ;
26+ download ( response . headers . location , to , done ) ;
2527 } else {
2628 console . error ( "Error downloading file:" , to , response . statusCode , response . statusMessage ) ;
2729 }
@@ -33,36 +35,34 @@ function download(url, to, done) {
3335}
3436
3537const osType = os . type ( ) ;
36- var downloadFileUrl ;
37- var downloadTo ;
38+ const arch = os . arch ( ) ;
39+ var binaryUrl ;
40+ var binaryName ;
3841
39- if ( osType === "Windows_NT" ) {
40- downloadFileUrl = `${ downloadFrom } npgsqlrest-win64.exe` ;
41- downloadTo = `${ downloadDir } npgsqlrest.exe` ;
42- } else if ( osType === "Linux" ) {
43- downloadFileUrl = `${ downloadFrom } npgsqlrest-linux64` ;
44- downloadTo = `${ downloadDir } npgsqlrest` ;
45- } else if ( osType === "Darwin" ) {
46- downloadFileUrl = `${ downloadFrom } npgsqlrest-osx-arm64` ;
47- downloadTo = `${ downloadDir } npgsqlrest` ;
42+ if ( osType === "Windows_NT" && arch === "x64" ) {
43+ binaryUrl = `${ downloadFrom } npgsqlrest-win64.exe` ;
44+ binaryName = "npgsqlrest.exe" ;
45+ } else if ( osType === "Linux" && arch === "x64" ) {
46+ binaryUrl = `${ downloadFrom } npgsqlrest-linux64` ;
47+ binaryName = "npgsqlrest" ;
48+ } else if ( osType === "Linux" && arch === "arm64" ) {
49+ binaryUrl = `${ downloadFrom } npgsqlrest-linux-arm64` ;
50+ binaryName = "npgsqlrest" ;
51+ } else if ( osType === "Darwin" && arch === "arm64" ) {
52+ binaryUrl = `${ downloadFrom } npgsqlrest-osx-arm64` ;
53+ binaryName = "npgsqlrest" ;
4854} else {
49- console . error ( " Unsupported OS detected:" , osType ) ;
55+ console . error ( ` Unsupported platform: ${ osType } ${ arch } ` ) ;
5056 process . exit ( 1 ) ;
5157}
5258
53- if ( ! fs . existsSync ( path . dirname ( downloadTo ) ) ) {
54- fs . mkdirSync ( path . dirname ( downloadTo ) , { recursive : true } ) ;
59+ if ( ! fs . existsSync ( binDir ) ) {
60+ fs . mkdirSync ( binDir , { recursive : true } ) ;
5561}
5662
57- if ( fs . existsSync ( downloadTo ) ) {
58- fs . unlinkSync ( downloadTo ) ;
63+ const binaryPath = path . join ( binDir , binaryName ) ;
64+ if ( fs . existsSync ( binaryPath ) ) {
65+ fs . unlinkSync ( binaryPath ) ;
5966}
60- download ( downloadFileUrl , downloadTo ) ;
61-
6267
63- downloadFileUrl = `${ downloadFrom } appsettings.json` ;
64- downloadTo = "./appsettings.json" ;
65- if ( fs . existsSync ( downloadFileUrl ) ) {
66- fs . unlinkSync ( downloadFileUrl , downloadTo ) ;
67- }
68- download ( downloadFileUrl , downloadTo ) ;
68+ download ( binaryUrl , binaryPath ) ;
0 commit comments