Skip to content

Commit 3f7cf49

Browse files
committed
Modify downloadBinary.js to improve comments and clarify the purpose of each section
1 parent 191dced commit 3f7cf49

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/commithelper-go/scripts/downloadBinary.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,50 @@ const {existsSync, mkdirSync, readFileSync} = require('fs')
44
const {platform, arch} = require('os')
55
const {join} = require('path')
66

7+
// Define the mapping of platform and architecture to the corresponding binary file names
78
const 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
1416
const key = `${platform()}-${arch()}`
1517
const binary = binaries[key]
1618

19+
// If the platform or architecture is not supported, exit with an error
1720
if (!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
2326
const packageJsonPath = join(__dirname, '../package.json')
2427
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
2528
const version = packageJson.version
2629

30+
// Construct the URL to download the binary from the GitHub releases
2731
const url = `https://github.com/NaverPayDev/cli/releases/download/v${version}/${binary}`
32+
33+
// Define the directory where the binary will be saved
2834
const binDir = join(__dirname, '../bin')
2935

36+
// Create the bin directory if it does not exist
3037
if (!existsSync(binDir)) {
3138
mkdirSync(binDir)
3239
}
3340

41+
// Define the full path where the binary will be saved
3442
const outputPath = join(binDir, binary)
3543

44+
// Log the download process
3645
console.log(`Downloading binary for ${key} from ${url}...`)
46+
47+
// Download the binary using curl and make it executable
3748
execSync(`curl -L ${url} -o ${outputPath} && chmod +x ${outputPath}`, {
3849
stdio: 'inherit',
3950
})
4051

52+
// Log the successful download
4153
console.log(`Binary downloaded to ${outputPath}`)

0 commit comments

Comments
 (0)