Skip to content

Commit aa11a0f

Browse files
authored
Add support to install tool via npm (#264)
1 parent b623013 commit aa11a0f

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

pkg/os/apk/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (d *CommonInstaller) Install() (err error) {
2828
return
2929
}
3030

31-
// Uninstall uninstalls the Conntrack
31+
// Uninstall uninstalls the target package
3232
func (d *CommonInstaller) Uninstall() (err error) {
3333
err = exec.RunCommand("apk", "del", d.Name)
3434
return
@@ -40,13 +40,13 @@ func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
4040
return
4141
}
4242

43-
// Start starts the Conntrack service
43+
// Start starts the target service
4444
func (d *CommonInstaller) Start() error {
4545
fmt.Println("not supported yet")
4646
return nil
4747
}
4848

49-
// Stop stops the Conntrack service
49+
// Stop stops the target service
5050
func (d *CommonInstaller) Stop() error {
5151
fmt.Println("not supported yet")
5252
return nil

pkg/os/generic_installer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/linuxsuren/http-downloader/pkg/os/apk"
66
"github.com/linuxsuren/http-downloader/pkg/os/dnf"
7+
"github.com/linuxsuren/http-downloader/pkg/os/npm"
78
"github.com/linuxsuren/http-downloader/pkg/os/snap"
89
"io/ioutil"
910
"runtime"
@@ -94,6 +95,10 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
9495
genericPackage.CommonInstaller = &dnf.CommonInstaller{
9596
Name: genericPackage.Name,
9697
}
98+
case npm.NPMName:
99+
genericPackage.CommonInstaller = &npm.CommonInstaller{
100+
Name: genericPackage.Name,
101+
}
97102
default:
98103
genericPackage.CommonInstaller = &generic.CommonInstaller{
99104
Name: genericPackage.Name,

pkg/os/npm/common.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package npm
2+
3+
import (
4+
"fmt"
5+
"github.com/linuxsuren/http-downloader/pkg/exec"
6+
)
7+
8+
// NPMName is the name of npm
9+
const NPMName = "npm"
10+
11+
// CommonInstaller is the installer of a common npm
12+
type CommonInstaller struct {
13+
Name string
14+
}
15+
16+
// Available check if support current platform
17+
func (d *CommonInstaller) Available() (ok bool) {
18+
_, err := exec.LookPath("npm")
19+
ok = err == nil
20+
return
21+
}
22+
23+
// Install installs the target package
24+
func (d *CommonInstaller) Install() (err error) {
25+
err = exec.RunCommand("npm", "i", "-g", d.Name)
26+
return
27+
}
28+
29+
// Uninstall uninstalls the target package
30+
func (d *CommonInstaller) Uninstall() (err error) {
31+
err = exec.RunCommand("npm", "uninstall", "-g", d.Name)
32+
return
33+
}
34+
35+
// WaitForStart waits for the service be started
36+
func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
37+
ok = true
38+
return
39+
}
40+
41+
// Start starts the target service
42+
func (d *CommonInstaller) Start() error {
43+
fmt.Println("not supported yet")
44+
return nil
45+
}
46+
47+
// Stop stops the target service
48+
func (d *CommonInstaller) Stop() error {
49+
fmt.Println("not supported yet")
50+
return nil
51+
}

0 commit comments

Comments
 (0)