diff --git a/.changeset/commithelper-go.md b/.changeset/commithelper-go.md new file mode 100644 index 0000000..f06cb9c --- /dev/null +++ b/.changeset/commithelper-go.md @@ -0,0 +1,5 @@ +--- +"@naverpay/commithelper-go": major +--- + +Initial major release with core features. diff --git a/packages/commithelper-go/bin/cli.js b/packages/commithelper-go/bin/cli.js new file mode 100644 index 0000000..3f2e985 --- /dev/null +++ b/packages/commithelper-go/bin/cli.js @@ -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) diff --git a/packages/commithelper-go/bin/commithelper-go b/packages/commithelper-go/bin/commithelper-go deleted file mode 100755 index e733786..0000000 Binary files a/packages/commithelper-go/bin/commithelper-go and /dev/null differ diff --git a/packages/commithelper-go/bin/commithelper-go-darwin-amd64 b/packages/commithelper-go/bin/commithelper-go-darwin-amd64 deleted file mode 100755 index 9e49821..0000000 Binary files a/packages/commithelper-go/bin/commithelper-go-darwin-amd64 and /dev/null differ diff --git a/packages/commithelper-go/bin/commithelper-go-darwin-arm64 b/packages/commithelper-go/bin/commithelper-go-darwin-arm64 deleted file mode 100755 index e733786..0000000 Binary files a/packages/commithelper-go/bin/commithelper-go-darwin-arm64 and /dev/null differ diff --git a/packages/commithelper-go/bin/commithelper-go-linux-amd64 b/packages/commithelper-go/bin/commithelper-go-linux-amd64 deleted file mode 100755 index 0579d04..0000000 Binary files a/packages/commithelper-go/bin/commithelper-go-linux-amd64 and /dev/null differ diff --git a/packages/commithelper-go/bin/commithelper-go-windows-amd64.exe b/packages/commithelper-go/bin/commithelper-go-windows-amd64.exe deleted file mode 100755 index 4ca9103..0000000 Binary files a/packages/commithelper-go/bin/commithelper-go-windows-amd64.exe and /dev/null differ diff --git a/packages/commithelper-go/package.json b/packages/commithelper-go/package.json index d542605..e6b4997 100644 --- a/packages/commithelper-go/package.json +++ b/packages/commithelper-go/package.json @@ -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", diff --git a/packages/commithelper-go/scripts/downloadBinary.js b/packages/commithelper-go/scripts/downloadBinary.js index 829ee35..a6e7cb8 100644 --- a/packages/commithelper-go/scripts/downloadBinary.js +++ b/packages/commithelper-go/scripts/downloadBinary.js @@ -4,6 +4,9 @@ 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', @@ -11,31 +14,57 @@ const binaries = { '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.') diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0d41157..ac51ade 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,6 +67,8 @@ importers: specifier: ^5.2.2 version: 5.3.3 + packages/commithelper-go: {} + packages/fmb: dependencies: chalk: