1 |
|
2 |
|
3 |
|
4 | module.exports = explore
|
5 | explore.usage = "npm explore <pkg> [ -- <cmd>]"
|
6 | explore.completion = require("./utils/completion/installed-shallow.js")
|
7 |
|
8 | var npm = require("./npm.js")
|
9 | , spawn = require("./utils/spawn")
|
10 | , path = require("path")
|
11 | , fs = require("graceful-fs")
|
12 |
|
13 | function explore (args, cb) {
|
14 | if (args.length < 1 || !args[0]) return cb(explore.usage)
|
15 | var p = args.shift()
|
16 | args = args.join(" ").trim()
|
17 | if (args) args = ["-c", args]
|
18 | else args = []
|
19 |
|
20 | var cwd = path.resolve(npm.dir, p)
|
21 | var sh = npm.config.get("shell")
|
22 | fs.stat(cwd, function (er, s) {
|
23 | if (er || !s.isDirectory()) return cb(new Error(
|
24 | "It doesn't look like "+p+" is installed."))
|
25 | if (!args.length) console.log(
|
26 | "\nExploring "+cwd+"\n"+
|
27 | "Type 'exit' or ^D when finished\n")
|
28 |
|
29 | npm.spinner.stop()
|
30 | var shell = spawn(sh, args, { cwd: cwd, stdio: "inherit" })
|
31 | shell.on("close", function (er) {
|
32 |
|
33 | if (!args.length) return cb()
|
34 | cb(er)
|
35 | })
|
36 | })
|
37 | }
|