@@ -4,38 +4,50 @@ const {existsSync, mkdirSync, readFileSync} = require('fs')
4
4
const { platform, arch} = require ( 'os' )
5
5
const { join} = require ( 'path' )
6
6
7
+ // Define the mapping of platform and architecture to the corresponding binary file names
7
8
const binaries = {
8
9
'darwin-x64' : 'commithelper-go-darwin-amd64' ,
9
10
'darwin-arm64' : 'commithelper-go-darwin-arm64' ,
10
11
'linux-x64' : 'commithelper-go-linux-amd64' ,
11
12
'win32-x64' : 'commithelper-go-windows-amd64.exe' ,
12
13
}
13
14
15
+ // Determine the current platform and architecture
14
16
const key = `${ platform ( ) } -${ arch ( ) } `
15
17
const binary = binaries [ key ]
16
18
19
+ // If the platform or architecture is not supported, exit with an error
17
20
if ( ! binary ) {
18
21
console . error ( `Unsupported platform: ${ platform ( ) } ${ arch ( ) } ` )
19
22
process . exit ( 1 )
20
23
}
21
24
22
- // Read version from package.json
25
+ // Read the version from the package.json file
23
26
const packageJsonPath = join ( __dirname , '../package.json' )
24
27
const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf-8' ) )
25
28
const version = packageJson . version
26
29
30
+ // Construct the URL to download the binary from the GitHub releases
27
31
const url = `https://github.com/NaverPayDev/cli/releases/download/v${ version } /${ binary } `
32
+
33
+ // Define the directory where the binary will be saved
28
34
const binDir = join ( __dirname , '../bin' )
29
35
36
+ // Create the bin directory if it does not exist
30
37
if ( ! existsSync ( binDir ) ) {
31
38
mkdirSync ( binDir )
32
39
}
33
40
41
+ // Define the full path where the binary will be saved
34
42
const outputPath = join ( binDir , binary )
35
43
44
+ // Log the download process
36
45
console . log ( `Downloading binary for ${ key } from ${ url } ...` )
46
+
47
+ // Download the binary using curl and make it executable
37
48
execSync ( `curl -L ${ url } -o ${ outputPath } && chmod +x ${ outputPath } ` , {
38
49
stdio : 'inherit' ,
39
50
} )
40
51
52
+ // Log the successful download
41
53
console . log ( `Binary downloaded to ${ outputPath } ` )
0 commit comments