gode

package module
v2.3.13+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2015 License: ISC Imports: 15 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 DefaultNodeVersion = "1.1.0"

The Node version to install. Override this by setting client.Version.

View Source
const DefaultNpmVersion = "2.4.1"

The NPM version to install. Override this by setting client.Version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	RootPath    string
	NodeVersion string
	NpmVersion  string
	Registry    string
}

Client is the interface between Node and Go. It also setups up the Node environment if needed.

func NewClient

func NewClient(rootPath string) *Client

NewClient creates a new Client at the specified rootPath The Node installation can then be setup here with client.Setup()

func (*Client) DebugScript

func (c *Client) DebugScript(script string) *exec.Cmd

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

func (*Client) InstallPackage

func (c *Client) InstallPackage(name string) error

InstallPackage installs an npm package.

func (*Client) IsSetup

func (c *Client) IsSetup() bool

IsSetup returns true if node is setup in the client's RootPath directory

func (*Client) NodeBase

func (c *Client) NodeBase() string

NodeBase returns the directory name for the node install

func (*Client) Packages

func (c *Client) Packages() ([]Package, error)

Packages returns a list of npm packages installed.

func (*Client) RemovePackage

func (c *Client) RemovePackage(name string) error

RemovePackage removes an npm package.

func (*Client) RunScript

func (c *Client) RunScript(script string) *exec.Cmd

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

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

hello world!

func (*Client) Setup

func (c *Client) Setup() error

Setup downloads and sets up node in the client's RootPath directory

func (*Client) UpdatePackage

func (c *Client) UpdatePackage(name string) (string, error)

UpdatePackage updates a package.

func (*Client) UpdatePackages

func (c *Client) UpdatePackages() (string, error)

UpdatePackages updates all packages.

type Package

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

Package represents an npm package.

Jump to

Keyboard shortcuts

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