gode

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2021 License: Apache-2.0, MIT, ISC Imports: 20 Imported by: 1

README

gode

Build Status Code Coverage GoDoc

gode runs a sandboxed node installation to run node code and install npm packages.

Usage

Gode will autoinstall Node and npm if it's not in the specified working directory.

To use gode, first give it a working directory. In this case, ~/.gode. You would need to already have a homeDir variable for this to work.

c := NewClient(filepath.Join(homeDir, ".gode"))

Next, call c.Setup() to ensure that gode is setup properly in that working directory.

err := c.Setup()
if err != nil {
    panic(err)
}

Finally, execute a node script. This returns an *os/exec.Cmd:

output, err := c.RunScript(`console.log("hello world!")`).CombinedOutput()
if err != nil {
    panic(err)
}
fmt.Println(string(output))

Or install packages:

err := c.InstallPackages("request")
if err != nil {
    panic(err)
}

Meta

Documentation

Overview

Package gode runs a sandboxed node installation to run node code and install npm packages.

Index

Examples

Constants

View Source
const NpmVersion = "6.13.7"

NpmVersion is the requested npm version

View Source
const Version = "12.16.1"

Version is the requested node version

Variables

This section is empty.

Functions

func ClearCache

func ClearCache() error

ClearCache clears the npm cache

func DebugScript

func DebugScript(script string) *exec.Cmd

DebugScript is the same as RunScript except it launches with node-inspector

func InstallPackages

func InstallPackages(packages ...string) error

InstallPackages installs a npm packages.

func IsSetup

func IsSetup() (bool, error)

IsSetup returns true if node is setup in RootPath

func NeedsUpdate

func NeedsUpdate() (bool, error)

NeedsUpdate returns true if it is using a node that isn't the latest version

func OutdatedPackages

func OutdatedPackages(names ...string) (map[string]string, error)

OutdatedPackages returns a map of packages and their latest version

func RebuildPackages added in v1.0.0

func RebuildPackages() error

RebuildPackages rebuilds installed npm packages.

func RemovePackages

func RemovePackages(packages ...string) error

RemovePackages removes a npm packages.

func RunScript

func RunScript(script string) *exec.Cmd

RunScript runs a given script in node Returns an *os/exec.Cmd instance

Example
SetRootPath(os.TempDir())
err := Setup()
if err != nil {
	panic(err)
}
cmd := RunScript(`console.log("hello world!")`)
output, err := cmd.CombinedOutput()
if err != nil {
	panic(err)
}
fmt.Println(string(output))
Output:

hello world!

func SetRootPath

func SetRootPath(root string)

SetRootPath sets the root for gode

func Setup

func Setup() error

Setup downloads and sets up node in the RootPath directory

Types

type Package

type Package struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Package represents an npm package.

func Packages

func Packages() ([]Package, error)

Packages returns a list of npm packages installed.

type Target

type Target struct {
	Arch string
	OS   string
	URL  string
	Base string
	Sha  string
}

Target represents a node tarball

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL