@@ -4,38 +4,50 @@ const {existsSync, mkdirSync, readFileSync} = require('fs')
44const { platform, arch} = require ( 'os' )
55const { join} = require ( 'path' )
66
7+ // Define the mapping of platform and architecture to the corresponding binary file names
78const binaries = {
89 'darwin-x64' : 'commithelper-go-darwin-amd64' ,
910 'darwin-arm64' : 'commithelper-go-darwin-arm64' ,
1011 'linux-x64' : 'commithelper-go-linux-amd64' ,
1112 'win32-x64' : 'commithelper-go-windows-amd64.exe' ,
1213}
1314
15+ // Determine the current platform and architecture
1416const key = `${ platform ( ) } -${ arch ( ) } `
1517const binary = binaries [ key ]
1618
19+ // If the platform or architecture is not supported, exit with an error
1720if ( ! binary ) {
1821 console . error ( `Unsupported platform: ${ platform ( ) } ${ arch ( ) } ` )
1922 process . exit ( 1 )
2023}
2124
22- // Read version from package.json
25+ // Read the version from the package.json file
2326const packageJsonPath = join ( __dirname , '../package.json' )
2427const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf-8' ) )
2528const version = packageJson . version
2629
30+ // Construct the URL to download the binary from the GitHub releases
2731const url = `https://github.com/NaverPayDev/cli/releases/download/v${ version } /${ binary } `
32+
33+ // Define the directory where the binary will be saved
2834const binDir = join ( __dirname , '../bin' )
2935
36+ // Create the bin directory if it does not exist
3037if ( ! existsSync ( binDir ) ) {
3138 mkdirSync ( binDir )
3239}
3340
41+ // Define the full path where the binary will be saved
3442const outputPath = join ( binDir , binary )
3543
44+ // Log the download process
3645console . log ( `Downloading binary for ${ key } from ${ url } ...` )
46+
47+ // Download the binary using curl and make it executable
3748execSync ( `curl -L ${ url } -o ${ outputPath } && chmod +x ${ outputPath } ` , {
3849 stdio : 'inherit' ,
3950} )
4051
52+ // Log the successful download
4153console . log ( `Binary downloaded to ${ outputPath } ` )
0 commit comments