Skip to content

Commit

Permalink
Add support to install tool via npm (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed May 24, 2022
1 parent b623013 commit aa11a0f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/os/apk/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (d *CommonInstaller) Install() (err error) {
return
}

// Uninstall uninstalls the Conntrack
// Uninstall uninstalls the target package
func (d *CommonInstaller) Uninstall() (err error) {
err = exec.RunCommand("apk", "del", d.Name)
return
Expand All @@ -40,13 +40,13 @@ func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
return
}

// Start starts the Conntrack service
// Start starts the target service
func (d *CommonInstaller) Start() error {
fmt.Println("not supported yet")
return nil
}

// Stop stops the Conntrack service
// Stop stops the target service
func (d *CommonInstaller) Stop() error {
fmt.Println("not supported yet")
return nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/os/generic_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/linuxsuren/http-downloader/pkg/os/apk"
"github.com/linuxsuren/http-downloader/pkg/os/dnf"
"github.com/linuxsuren/http-downloader/pkg/os/npm"
"github.com/linuxsuren/http-downloader/pkg/os/snap"
"io/ioutil"
"runtime"
Expand Down Expand Up @@ -94,6 +95,10 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
genericPackage.CommonInstaller = &dnf.CommonInstaller{
Name: genericPackage.Name,
}
case npm.NPMName:
genericPackage.CommonInstaller = &npm.CommonInstaller{
Name: genericPackage.Name,
}
default:
genericPackage.CommonInstaller = &generic.CommonInstaller{
Name: genericPackage.Name,
Expand Down
51 changes: 51 additions & 0 deletions pkg/os/npm/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package npm

import (
"fmt"
"github.com/linuxsuren/http-downloader/pkg/exec"
)

// NPMName is the name of npm
const NPMName = "npm"

// CommonInstaller is the installer of a common npm
type CommonInstaller struct {
Name string
}

// Available check if support current platform
func (d *CommonInstaller) Available() (ok bool) {
_, err := exec.LookPath("npm")
ok = err == nil
return
}

// Install installs the target package
func (d *CommonInstaller) Install() (err error) {
err = exec.RunCommand("npm", "i", "-g", d.Name)
return
}

// Uninstall uninstalls the target package
func (d *CommonInstaller) Uninstall() (err error) {
err = exec.RunCommand("npm", "uninstall", "-g", d.Name)
return
}

// WaitForStart waits for the service be started
func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
ok = true
return
}

// Start starts the target service
func (d *CommonInstaller) Start() error {
fmt.Println("not supported yet")
return nil
}

// Stop stops the target service
func (d *CommonInstaller) Stop() error {
fmt.Println("not supported yet")
return nil
}

0 comments on commit aa11a0f

Please sign in to comment.