gode

package
v4.27.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: MIT, ISC Imports: 20 Imported by: 0

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.InstallPackage("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 = "3.3.10"

NpmVersion is the requested npm version

View Source
const Version = "5.0.0"

Version is the requested node version

Variables

This section is empty.

Functions

func DebugScript

func DebugScript(script string) *exec.Cmd

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

func InstallPackage

func InstallPackage(packages ...string) error

InstallPackage installs an npm package.

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 RemovePackage

func RemovePackage(name string) error

RemovePackage removes an npm package.

func RunScript

func RunScript(script string) *exec.Cmd

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

Example
SetRootPath("tmp")
err := Setup()
if err != nil {
	panic(err)
}
output, err := RunScript(`console.log("hello world!")`).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

func UpdatePackage

func UpdatePackage(name string) (string, error)

UpdatePackage updates a package.

func UpdatePackages

func UpdatePackages() (string, error)

UpdatePackages updates all packages.

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