import { funcPackageName , PackageManager } from '../constants' ; import { FuncVersion } from '../FuncVersion' ; import { cpUtils } from '../utils/cpUtils' ; import { tryGetInstalledBrewPackageName } from './getBrewPackageName' ; export async function getFuncPackageManagers ( isFuncInstalled ) { const result = [ ] ; switch ( process . platform ) { case 'linux' : break ; case 'darwin' : if ( await hasBrew ( isFuncInstalled ) ) { result . push ( PackageManager . brew ) ; } default : try { isFuncInstalled ? await cpUtils . executeCommand ( undefined , undefined , 'npm' , 'ls' , '-g' , funcPackageName ) : await cpUtils . executeCommand ( undefined , undefined , 'npm' , '--version' ) ; result . push ( PackageManager . npm ) ; } catch ( error ) { } } return result ; } async function hasBrew ( isFuncInstalled ) { for ( const version of Object . values ( FuncVersion ) ) { if ( version !== FuncVersion . v1 ) { if ( isFuncInstalled ) { const packageName = await tryGetInstalledBrewPackageName ( version ) ; if ( packageName ) { return true ; } } else { try { await cpUtils . executeCommand ( undefined , undefined , 'brew' , '--version' ) ; return true ; } catch ( error ) { } } } } return false ; }