From 0e5b05823aa3b0272024a6ff8510adff2e375051 Mon Sep 17 00:00:00 2001 From: Michael Alexander Date: Sun, 20 May 2012 09:14:43 +0800 Subject: [PATCH] Added exec command. --- doc/cli/exec.md | 15 +++++++++++++++ lib/exec.js | 18 ++++++++++++++++++ lib/npm.js | 1 + 3 files changed, 34 insertions(+) create mode 100644 doc/cli/exec.md create mode 100644 lib/exec.js diff --git a/doc/cli/exec.md b/doc/cli/exec.md new file mode 100644 index 00000000000..ed91d517c1a --- /dev/null +++ b/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) diff --git a/lib/exec.js b/lib/exec.js new file mode 100644 index 00000000000..91e6cfbda6c --- /dev/null +++ b/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) }) + }) +} diff --git a/lib/npm.js b/lib/npm.js index 2db21e34def..0705fb1ddc6 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -156,6 +156,7 @@ var commandCache = {} , "restart" , "run-script" , "completion" + , "exec" ] , plumbing = [ "build" , "unbuild"