diff --git a/packages/core/installMachine/installSteps/github/ghInstaller.ts b/packages/core/installMachine/installSteps/github/ghInstaller.ts index 4d9af0c..75aab7c 100644 --- a/packages/core/installMachine/installSteps/github/ghInstaller.ts +++ b/packages/core/installMachine/installSteps/github/ghInstaller.ts @@ -1,17 +1,31 @@ -import { execSync } from 'child_process'; import * as os from 'os'; import { logger } from '../../../utils/logger'; +import { execAsync } from '../../../utils/execAsync'; -export const isGitHubCLIInstalled = (): boolean => { +const getLinuxDistro = async (): Promise => { try { - execSync('gh --version', { stdio: 'ignore' }); + const osRelease = execAsync('cat /etc/os-release').toString(); + if (osRelease.includes('Ubuntu')) return 'ubuntu'; + if (osRelease.includes('Debian')) return 'debian'; + if (osRelease.includes('Fedora')) return 'fedora'; + if (osRelease.includes('CentOS')) return 'centos'; + if (osRelease.includes('Red Hat')) return 'rhel'; + return 'unknown'; + } catch (error) { + return 'unknown'; + } +}; + +export const isGitHubCLIInstalled = async (): Promise => { + try { + await execAsync('gh --version'); return true; } catch (error) { return false; } }; -export const installGitHubCLI = (): boolean => { +export const installGitHubCLI = async (): Promise => { const platform = os.platform(); let installCommand: string; @@ -20,7 +34,10 @@ export const installGitHubCLI = (): boolean => { installCommand = 'brew install gh'; break; case 'linux': // Linux - const linuxDistro = getLinuxDistro(); + const linuxDistro = await getLinuxDistro(); + if (linuxDistro === 'unknown') { + logger.log('github', 'Automatic installation is not supported for your Linux distribution.'); + } if (linuxDistro === 'ubuntu' || linuxDistro === 'debian') { installCommand = 'sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 && sudo apt-add-repository https://cli.github.com/packages && sudo apt update && sudo apt install gh'; @@ -48,7 +65,7 @@ export const installGitHubCLI = (): boolean => { logger.log('github', 'Installing GitHub CLI...'); try { - execSync(installCommand, { stdio: 'inherit' }); + await execAsync(installCommand); return true; } catch (error) { console.error('Failed to install GitHub CLI.'); @@ -56,17 +73,3 @@ export const installGitHubCLI = (): boolean => { return false; } }; - -export const getLinuxDistro = (): string => { - try { - const osRelease = execSync('cat /etc/os-release').toString(); - if (osRelease.includes('Ubuntu')) return 'ubuntu'; - if (osRelease.includes('Debian')) return 'debian'; - if (osRelease.includes('Fedora')) return 'fedora'; - if (osRelease.includes('CentOS')) return 'centos'; - if (osRelease.includes('Red Hat')) return 'rhel'; - return 'unknown'; - } catch (error) { - return 'unknown'; - } -}; diff --git a/packages/core/installMachine/installSteps/github/install.ts b/packages/core/installMachine/installSteps/github/install.ts index 1cbf668..e0010c8 100644 --- a/packages/core/installMachine/installSteps/github/install.ts +++ b/packages/core/installMachine/installSteps/github/install.ts @@ -30,7 +30,7 @@ const checkGitHubCLI = async () => { ]); if (shouldInstallGitHubCLI) { - const installed = installGitHubCLI(); + const installed = await installGitHubCLI(); if (!installed) { spinner.fail('GitHub CLI installation failed. Exiting...'); console.error('GitHub CLI installation failed. Exiting...');