Skip to content

Commit

Permalink
Added exec command.
Browse files Browse the repository at this point in the history
  • Loading branch information
beefsack committed May 20, 2012
1 parent c0e521a commit 0e5b058
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/cli/exec.md
@@ -0,0 +1,15 @@
npm-exec(1) -- Add local package binaries to path and execute command
====================================

## SYNOPSIS

npm exec

## DESCRIPTION

Adds the local package bin path (eg. node_modules/.bin) before executing the
command.

## SEE ALSO

* npm-bin(1)
18 changes: 18 additions & 0 deletions lib/exec.js
@@ -0,0 +1,18 @@
module.exports = exec

var npm = require("./npm.js")
, output = require("./utils/output.js")

exec.usage = "npm exec\n(add local package binaries to path and execute command)"

function exec (args, cb) {
var path = require("path")
, b = npm.bin
, PATH = (process.env.PATH || "").split(":")
, exec = require("child_process").exec

var cmd = "PATH=" + b + ":$PATH " + args.join(" ")
exec(cmd, function (error, stdout, stderr) {
output.write(stdout, function (er) { cb(er, stdout) })
})
}
1 change: 1 addition & 0 deletions lib/npm.js
Expand Up @@ -156,6 +156,7 @@ var commandCache = {}
, "restart"
, "run-script"
, "completion"
, "exec"
]
, plumbing = [ "build"
, "unbuild"
Expand Down

0 comments on commit 0e5b058

Please sign in to comment.