Passed
Pull Request — develop (#65)
by
unknown
04:01 queued 02:39
created

src/client/packageManager/homebrew.ts   A

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 71
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 8
mnd 2
bc 2
fnc 6
bpm 0.3333
cpm 1.3333
noi 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A Homebrew.packageIsInstalled 0 10 1
A Homebrew.install 0 17 2
A Homebrew.uninstall 0 17 2
A Homebrew.remove 0 4 1
A Homebrew.update 0 3 1
A Homebrew.upgrade 0 4 1
1
import execa from 'execa'
2
import PackageManager from '../packageManager'
3
4
class Homebrew extends PackageManager {
5
    alias = 'brew'
6
    name = 'Homebrew'
7
    path = '/usr/local/bin/brew'
8
9
    /**
10
     * Install 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 = false): Promise<boolean> {
16
        let args: string[] = ['install', pkg]
17
18
        if (cask) {
19
            args = ['install', 'cask', pkg]
20
        }
21
22
        const {stdout} = await execa('brew', args, {shell: true})
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 = false): Promise<boolean> {
34
        let args: string[] = ['remove', pkg]
35
36
        if (cask) {
37
            args = ['remove', 'cask', pkg]
38
        }
39
40
        const {stdout} = await execa('brew', args, {shell: true})
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'], {shell: true})
52
53
        return stdout.includes(pkg)
54
    }
55
56
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
    remove(pkg: string): Promise<boolean> {
58
        return Promise.resolve(false)
59
    }
60
61
    update(): Promise<boolean> {
62
        return Promise.resolve(false)
63
    }
64
65
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
    upgrade(pkg: string | undefined): Promise<boolean> {
67
        return Promise.resolve(false)
68
    }
69
}
70
71
export default Homebrew