UNPKG

fire-code-cli

Version:

AI-powered coding assistant for the terminal. A ChatGPT-like CLI tool built with React Ink and Fireworks AI.

102 lines (86 loc) 2.44 kB
const fs = require('fs'); const path = require('path'); const os = require('os'); const { execSync } = require('child_process'); function getPlatform() { const platform = os.platform(); const arch = os.arch(); // Map Node.js platform/arch to our package names const platformMap = { darwin: { arm64: 'darwin-arm64', x64: 'darwin-x64', }, linux: { x64: 'linux-x64', arm64: 'linux-arm64', }, win32: { x64: 'windows-x64', }, }; if (!platformMap[platform]?.[arch]) { throw new Error(`Unsupported platform: ${platform}-${arch}`); } return platformMap[platform][arch]; } function getBinaryName(platform) { return platform.includes('windows') ? 'firecode.exe' : 'firecode'; } function getBinaryPath() { const platform = getPlatform(); const binaryName = getBinaryName(platform); // First, check if binary exists in the main package bin directory const mainBinPath = path.join(__dirname, '..', 'bin', binaryName); if (fs.existsSync(mainBinPath)) { return mainBinPath; } // Second, check platform-specific package const platformPackagePath = path.join( __dirname, '..', 'node_modules', `fire-code-${platform}`, 'bin', binaryName, ); if (fs.existsSync(platformPackagePath)) { return platformPackagePath; } // Third, check dist directory (development scenario) const distBinaryPath = path.join( __dirname, '..', 'dist', `firecode-${platform}${platform.includes('windows') ? '.exe' : ''}`, ); if (fs.existsSync(distBinaryPath)) { return distBinaryPath; } // If none found, try to download or use fallback return downloadBinary(); } function downloadBinary() { // This is a simplified version - in production you'd want to download from GitHub releases // or another CDN where your binaries are hosted const platform = getPlatform(); console.warn(`Binary not found for platform ${platform}`); console.warn( 'Please ensure the appropriate platform package is installed or build the project locally.', ); throw new Error(`No binary available for platform: ${platform}`); } function execBinary(args = []) { const binaryPath = getBinaryPath(); const result = execSync(`"${binaryPath}" ${args.join(' ')}`, { stdio: 'inherit', encoding: 'utf8', }); return result; } module.exports = { getBinaryPath, getPlatform, getBinaryName, execBinary, };