@@ -4,6 +4,8 @@ const {existsSync, mkdirSync, readFileSync} = require('fs')
4
4
const { platform, arch} = require ( 'os' )
5
5
const { join} = require ( 'path' )
6
6
7
+ console . log ( 'Starting postinstall script: downloadBinary.js' )
8
+
7
9
// Define the mapping of platform and architecture to the corresponding binary file names
8
10
const binaries = {
9
11
'darwin-x64' : 'commithelper-go-darwin-amd64' ,
@@ -16,6 +18,9 @@ const binaries = {
16
18
const key = `${ platform ( ) } -${ arch ( ) } `
17
19
const binary = binaries [ key ]
18
20
21
+ console . log ( `Detected platform: ${ platform ( ) } , architecture: ${ arch ( ) } ` )
22
+ console . log ( `Selected binary: ${ binary } ` )
23
+
19
24
// If the platform or architecture is not supported, exit with an error
20
25
if ( ! binary ) {
21
26
console . error ( `Unsupported platform: ${ platform ( ) } ${ arch ( ) } ` )
@@ -29,25 +34,37 @@ const version = packageJson.version
29
34
30
35
// Construct the URL to download the binary from the GitHub releases
31
36
const url = `https://github.com/NaverPayDev/cli/releases/download/v${ version } /${ binary } `
37
+ console . log ( `Constructed URL: ${ url } ` )
32
38
33
39
// Define the directory where the binary will be saved
34
40
const binDir = join ( __dirname , '../bin' )
35
41
36
42
// Create the bin directory if it does not exist
37
43
if ( ! existsSync ( binDir ) ) {
38
44
mkdirSync ( binDir )
45
+ console . log ( `Created bin directory: ${ binDir } ` )
39
46
}
40
47
41
48
// Define the full path where the binary will be saved
42
49
const outputPath = join ( binDir , binary )
43
-
44
- // Log the download process
45
- console . log ( `Downloading binary for ${ key } from ${ url } ...` )
50
+ console . log ( `Binary will be saved to: ${ outputPath } ` )
46
51
47
52
// Download the binary using curl and make it executable
48
- execSync ( `curl -L ${ url } -o ${ outputPath } && chmod +x ${ outputPath } ` , {
49
- stdio : 'inherit' ,
50
- } )
53
+ try {
54
+ execSync ( `curl -L ${ url } -o ${ outputPath } ` , { stdio : 'inherit' } )
55
+ console . log ( `Binary successfully downloaded to: ${ outputPath } ` )
56
+ } catch ( error ) {
57
+ console . error ( `Failed to download binary: ${ error . message } ` )
58
+ process . exit ( 1 )
59
+ }
60
+
61
+ // Add execution permission to the binary
62
+ try {
63
+ execSync ( `chmod +x ${ outputPath } ` , { stdio : 'inherit' } )
64
+ console . log ( `Execution permission added to binary: ${ outputPath } ` )
65
+ } catch ( error ) {
66
+ console . error ( `Failed to set execution permission: ${ error . message } ` )
67
+ process . exit ( 1 )
68
+ }
51
69
52
- // Log the successful download
53
- console . log ( `Binary downloaded to ${ outputPath } ` )
70
+ console . log ( 'Postinstall script completed successfully.' )
0 commit comments