| 1 |  |  | import execa from 'execa' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | import PackageManager from '../packageManager' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | class Homebrew extends PackageManager { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |     private static instance: Homebrew; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     alias: string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     name: string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     path: string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     private constructor() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         super() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         let usrLocalDir | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         switch (`${process.platform}_${process.arch}`) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         case 'darwin_arm64': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             usrLocalDir = '/opt/homebrew' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             break | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         default: // darwin x64 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             usrLocalDir = '/usr/local' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             break | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         this.alias = 'brew' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         this.name = 'Homebrew' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         this.path = `${usrLocalDir}/bin/brew` | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     public static getInstance(): PackageManager { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         if (!Homebrew.instance) { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             Homebrew.instance = new Homebrew() | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         return Homebrew.instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * Install a package. In case of brew, the cask variable should be true of it ain't a formula but a cask. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param pkg | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param cask | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     async install(pkg: string, cask = false): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         let args: string[] = ['install', pkg] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         if (cask) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             args = ['install', 'cask', pkg] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         const {stdout} = await execa('brew', args, {shell: true}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         return stdout.includes(pkg) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Uninstall a package. In case of brew, the cask variable should be true of it ain't a formula but a cask. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param pkg | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param cask | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     async uninstall(pkg: string, cask = false): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         let args: string[] = ['remove', pkg] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         if (cask) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             args = ['remove', 'cask', pkg] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         const {stdout} = await execa('brew', args, {shell: true}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return stdout.includes(pkg) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * Check if the pkg is installed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param pkg | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     async packageIsInstalled(pkg: string): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         const {stdout} = await execa('brew', ['list', '--formula'], {shell: true}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         return stdout.includes(pkg) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     // eslint-disable-next-line @typescript-eslint/no-unused-vars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     remove(pkg: string): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return Promise.resolve(false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     update(): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return Promise.resolve(false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     // eslint-disable-next-line @typescript-eslint/no-unused-vars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     upgrade(pkg: string | undefined): Promise<boolean> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return Promise.resolve(false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  | export default Homebrew | 
            
                                                        
            
                                    
            
            
                | 100 |  |  |  |