| import * as path from 'path'; |
|
|
| export interface Platform { |
| os: 'darwin' | 'linux' | 'windows'; |
| arch: 'amd64' | 'arm64'; |
| } |
|
|
| export function detectPlatform(): Platform { |
| const platform = process.platform as string; |
|
|
| |
| let arch: 'amd64' | 'arm64'; |
| if (process.arch === 'x64') { |
| arch = 'amd64'; |
| } else if (process.arch === 'arm64') { |
| arch = 'arm64'; |
| } else { |
| throw new Error( |
| `Unsupported architecture: ${process.arch}. ` + `Only x64 (amd64) and arm64 are supported.` |
| ); |
| } |
|
|
| const osMap: Record<string, 'darwin' | 'linux' | 'windows'> = { |
| darwin: 'darwin', |
| linux: 'linux', |
| win32: 'windows', |
| }; |
|
|
| const os_name = osMap[platform]; |
| if (!os_name) { |
| throw new Error(`Unsupported platform: ${platform}`); |
| } |
|
|
| return { os: os_name, arch }; |
| } |
|
|
| export function getBinaryName(platform: Platform): string { |
| const { os, arch } = platform; |
| const archName = arch === 'arm64' ? 'arm64' : 'amd64'; |
|
|
| if (os === 'windows') { |
| return `pinchtab-${os}-${archName}.exe`; |
| } |
| return `pinchtab-${os}-${archName}`; |
| } |
|
|
| export function getBinDir(): string { |
| return path.join(process.env.HOME || process.env.USERPROFILE || '', '.pinchtab', 'bin'); |
| } |
|
|
| export function getBinaryPath(binaryName: string, version?: string): string { |
| |
| if (process.env.PINCHTAB_BINARY_PATH) { |
| return process.env.PINCHTAB_BINARY_PATH; |
| } |
|
|
| |
| |
| if (version) { |
| return path.join(getBinDir(), version, binaryName); |
| } |
|
|
| |
| return path.join(getBinDir(), binaryName); |
| } |
|
|