Passed
Push — develop ( 4e05c7...30a60d )
by Bjarn
13:12 queued 08:58
created

src/tools/tool.ts   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 50
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 0
1
import {error, info, success} from '../utils/console'
2
import {client} from '../utils/os'
3
4
abstract class Tool {
5
6
    abstract name: string
7
    abstract alias: string
8
9
    /**
10
     * Install the app.
11
     */
12
    install = async (): Promise<boolean> => {
13
        if (await this.isInstalled()) {
14
            error(`${this.name} already is installed.`)
15
            return false
16
        }
17
18
        info(`Installing ${this.name}...`)
19
        await client().packageManager.install(this.alias, false)
20
        return true
21
    }
22
23
    /**
24
     * Uninstall the app.
25
     */
26
    uninstall = async (): Promise<boolean> => {
27
        if (!(await this.isInstalled())) {
28
            error(`${this.name} is not installed.`)
29
            return false
30
        }
31
32
        info(`Uninstalling ${this.name}...`)
33
34
        await client().packageManager.uninstall(this.alias, false)
35
36
        success(`Uninstalled ${this.name}.`)
37
38
        return true
39
    }
40
41
    /**
42
     * Check if app the is already installed..
43
     */
44
    isInstalled = async (): Promise<boolean> => {
45
        return client().packageManager.packageIsInstalled(this.alias)
46
    }
47
48
}
49
50
export default Tool