1
|
|
|
import execa from 'execa' |
2
|
|
|
import PackageManager from '../packageManager' |
3
|
|
|
|
4
|
|
|
class Homebrew extends PackageManager { |
5
|
|
|
alias: string = 'brew' |
6
|
|
|
name: string = 'Homebrew' |
7
|
|
|
path: string = '/usr/local/bin/brew' |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Uninstall a package. In case of brew, the cask variable should be true of it ain't a formula but a cask. |
11
|
|
|
* |
12
|
|
|
* @param pkg |
13
|
|
|
* @param cask |
14
|
|
|
*/ |
15
|
|
|
async install(pkg: string, cask: boolean = false): Promise<boolean> { |
16
|
|
|
let args: string[] = ['install', pkg] |
17
|
|
|
|
18
|
|
|
if (cask) { |
19
|
|
|
args = ['cask', 'install', pkg] |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
const {stdout} = await execa('brew', args) |
23
|
|
|
|
24
|
|
|
return stdout.includes(pkg) |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Uninstall a package. In case of brew, the cask variable should be true of it ain't a formula but a cask. |
29
|
|
|
* |
30
|
|
|
* @param pkg |
31
|
|
|
* @param cask |
32
|
|
|
*/ |
33
|
|
|
async uninstall(pkg: string, cask: boolean = false): Promise<boolean> { |
34
|
|
|
let args: string[] = ['remove', pkg] |
35
|
|
|
|
36
|
|
|
if (cask) { |
37
|
|
|
args = ['cask', 'remove', pkg] |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
const {stdout} = await execa('brew', args) |
41
|
|
|
|
42
|
|
|
return stdout.includes(pkg) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Check if the pkg is installed. |
47
|
|
|
* |
48
|
|
|
* @param pkg |
49
|
|
|
*/ |
50
|
|
|
async packageIsInstalled(pkg: string): Promise<boolean> { |
51
|
|
|
const {stdout} = await execa('brew', ['list', '--formula']) |
52
|
|
|
|
53
|
|
|
return stdout.includes(pkg) |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
remove(pkg: string): Promise<boolean> { |
57
|
|
|
return Promise.resolve(false) |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
update(): Promise<boolean> { |
61
|
|
|
return Promise.resolve(false) |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
upgrade(pkg: string | undefined): Promise<boolean> { |
65
|
|
|
return Promise.resolve(false) |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
export default Homebrew |