Passed
Push — main ( 6c7a2f...4e8e13 )
by Bjarn
03:31 queued 01:55
created

src/tools/tool.ts   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 48
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A Tool.isInstalled 0 2 1
A Tool.install 0 9 2
A Tool.uninstall 0 12 2
1
import {client} from '../utils/os'
2
3
abstract class Tool {
4
5
    abstract name: string
6
    abstract alias: string
7
8
    /**
9
     * Install the app.
10
     */
11
    install = async (): Promise<boolean> => {
12
        if (await this.isInstalled()) {
13
            console.log(`${this.name} already is installed`)
14
            return false
15
        }
16
17
        console.log(`Installing ${this.name}...`)
18
        await client().packageManager.install(this.alias, false)
19
        return true
20
    }
21
22
    /**
23
     * Uninstall the app.
24
     */
25
    uninstall = async (): Promise<boolean> => {
26
        if (!(await this.isInstalled())) {
27
            console.log(`${this.name} is not installed`)
28
        }
29
30
        console.log(`Uninstalling ${this.name}...`)
31
32
        await client().packageManager.uninstall(this.alias, false)
33
34
        console.log(`Installed ${this.name}`)
35
36
        return true
37
    }
38
39
    /**
40
     * Check if the is already installed..
41
     */
42
    isInstalled = async (): Promise<boolean> => {
43
        return client().packageManager.packageIsInstalled(this.alias)
44
    }
45
46
}
47
48
export default Tool