Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/commithelper-go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@naverpay/commithelper-go": major
---

Initial major release with core features.
27 changes: 27 additions & 0 deletions packages/commithelper-go/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node
const {spawnSync} = require('child_process')
const {platform, arch} = require('os')
const path = require('path')

const binaries = {
'darwin-x64': 'commithelper-go-darwin-amd64',
'darwin-arm64': 'commithelper-go-darwin-arm64',
'linux-x64': 'commithelper-go-linux-amd64',
'win32-x64': 'commithelper-go-windows-amd64.exe',
}

const key = `${platform()}-${arch()}`
const binaryName = binaries[key]

if (!binaryName) {
// eslint-disable-next-line no-console
console.error(`Unsupported platform: ${platform()} ${arch()}`)
process.exit(1)
}

const binaryPath = path.join(__dirname, binaryName)

const args = process.argv.slice(2)
const result = spawnSync(binaryPath, args, {stdio: 'inherit'})

process.exit(result.status)
Binary file removed packages/commithelper-go/bin/commithelper-go
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/commithelper-go/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"description": "A CLI tool to assist with commit messages based on branch names and configuration.",
"bin": {
"commithelper-go": "bin/commithelper-go"
"commithelper-go": "bin/cli.js"
},
"scripts": {
"build:windows": "GOOS=windows GOARCH=amd64 go build -o dist/commithelper-go-windows-amd64.exe main.go",
Expand Down
43 changes: 36 additions & 7 deletions packages/commithelper-go/scripts/downloadBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,67 @@ const {existsSync, mkdirSync, readFileSync} = require('fs')
const {platform, arch} = require('os')
const {join} = require('path')

console.log('Starting postinstall script: downloadBinary.js')

// Define the mapping of platform and architecture to the corresponding binary file names
const binaries = {
'darwin-x64': 'commithelper-go-darwin-amd64',
'darwin-arm64': 'commithelper-go-darwin-arm64',
'linux-x64': 'commithelper-go-linux-amd64',
'win32-x64': 'commithelper-go-windows-amd64.exe',
}

// Determine the current platform and architecture
const key = `${platform()}-${arch()}`
const binary = binaries[key]

console.log(`Detected platform: ${platform()}, architecture: ${arch()}`)
console.log(`Selected binary: ${binary}`)

// If the platform or architecture is not supported, exit with an error
if (!binary) {
console.error(`Unsupported platform: ${platform()} ${arch()}`)
process.exit(1)
}

// Read version from package.json
// Read the version from the package.json file
const packageJsonPath = join(__dirname, '../package.json')
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
const version = packageJson.version

const url = `https://github.com/NaverPayDev/cli/releases/download/v${version}/${binary}`
// Construct the URL to download the binary from the GitHub releases
const url = `https://github.com/NaverPayDev/cli/releases/download/@naverpay/commithelper-go@${version}/${binary}`
console.log(`Constructed URL: ${url}`)

// Define the directory where the binary will be saved
const binDir = join(__dirname, '../bin')

// Create the bin directory if it does not exist
if (!existsSync(binDir)) {
mkdirSync(binDir)
console.log(`Created bin directory: ${binDir}`)
}

// Define the full path where the binary will be saved
const outputPath = join(binDir, binary)
console.log(`Binary will be saved to: ${outputPath}`)

// Download the binary using curl and make it executable
try {
execSync(`curl -L ${url} -o ${outputPath}`, {stdio: 'inherit'})
console.log(`Binary successfully downloaded to: ${outputPath}`)
} catch (error) {
console.error(`Failed to download binary: ${error.message}`)
process.exit(1)
}

console.log(`Downloading binary for ${key} from ${url}...`)
execSync(`curl -L ${url} -o ${outputPath} && chmod +x ${outputPath}`, {
stdio: 'inherit',
})
// Add execution permission to the binary
try {
execSync(`chmod +x ${outputPath}`, {stdio: 'inherit'})
console.log(`Execution permission added to binary: ${outputPath}`)
} catch (error) {
console.error(`Failed to set execution permission: ${error.message}`)
process.exit(1)
}

console.log(`Binary downloaded to ${outputPath}`)
console.log('Postinstall script completed successfully.')
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.