UNPKG

@followthecode/cli

Version:

CLI tool for Git repository analysis and data collection

115 lines (96 loc) 3.44 kB
#!/usr/bin/env node const { spawn } = require('child_process'); const path = require('path'); const fs = require('fs'); // Detecta a plataforma const platform = process.platform; const isWindows = platform === 'win32'; // Caminho para o executável .NET baseado na plataforma function getExecutablePath() { const baseDir = path.join(__dirname); if (isWindows) { return path.join(baseDir, 'win-x64', 'ftc.cli.exe'); } else if (platform === 'darwin') { return path.join(baseDir, 'osx-x64', 'ftc.cli'); } else { return path.join(baseDir, 'linux-x64', 'ftc.cli'); } } // Verifica se o executável existe function checkExecutable() { const execPath = getExecutablePath(); if (!fs.existsSync(execPath)) { console.error('❌ Executável FTC CLI não encontrado!'); console.error(` Procurado em: ${execPath}`); console.error('💡 Execute "npm run build" para compilar o projeto.'); process.exit(1); } return execPath; } // Copia arquivo de configuração para o diretório atual function copyConfigFile() { try { const currentDir = process.cwd(); const configDest = path.join(currentDir, 'appsettings.json'); // Se já existe no diretório atual, não copia if (fs.existsSync(configDest)) { return; } // Tenta diferentes locais para o arquivo de configuração const possibleSources = [ path.join(__dirname, 'linux-x64', 'appsettings.json'), path.join(__dirname, 'win-x64', 'appsettings.json'), path.join(__dirname, 'osx-x64', 'appsettings.json'), path.join(__dirname, '..', 'appsettings.json') ]; let configSource = null; for (const source of possibleSources) { if (fs.existsSync(source)) { configSource = source; break; } } if (configSource) { fs.copyFileSync(configSource, configDest); } } catch (error) { // Ignora erros de cópia } } // Função principal function main() { try { // Verifica se o executável existe const execPath = checkExecutable(); // Copia arquivo de configuração para o diretório atual copyConfigFile(); // Define permissões de execução (Linux/macOS) if (!isWindows) { try { fs.chmodSync(execPath, 0o755); } catch (error) { // Ignora erros de permissão } } // Executa o CLI .NET const child = spawn(execPath, process.argv.slice(2), { stdio: 'inherit', cwd: process.cwd() }); child.on('error', (error) => { console.error('❌ Erro ao executar FTC CLI:', error.message); process.exit(1); }); child.on('close', (code) => { process.exit(code); }); } catch (error) { console.error('❌ Erro fatal:', error.message); process.exit(1); } } // Executa se for o arquivo principal if (require.main === module) { main(); } module.exports = { main, getExecutablePath, checkExecutable };