Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Support multiple packagenames in npm docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
timoxley authored and domenic committed Jan 8, 2014
1 parent 93fc364 commit 823010b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 5 additions & 4 deletions doc/cli/npm-docs.md
Expand Up @@ -3,17 +3,18 @@ npm-docs(1) -- Docs for a package in a web browser maybe


## SYNOPSIS ## SYNOPSIS


npm docs <pkgname> npm docs [<pkgname> [<pkgname> ...]]
npm docs (with no args in a package dir) npm docs (with no args in a package dir)
npm home <pkgname> npm home [<pkgname> [<pkgname> ...]]
npm home (with no args in a package dir) npm home (with no args in a package dir)


## DESCRIPTION ## DESCRIPTION


This command tries to guess at the likely location of a package's This command tries to guess at the likely location of a package's
documentation URL, and then tries to open it using the `--browser` documentation URL, and then tries to open it using the `--browser`
config param. If no package name is provided, it will search for config param. You can pass multiple package names at once. If no
a `package.json` in the current folder and use the `name` property. package name is provided, it will search for a `package.json` in
the current folder and use the `name` property.


## CONFIGURATION ## CONFIGURATION


Expand Down
17 changes: 14 additions & 3 deletions lib/docs.js
Expand Up @@ -5,7 +5,6 @@ docs.usage += "\n"
docs.usage += "npm docs ." docs.usage += "npm docs ."


docs.completion = function (opts, cb) { docs.completion = function (opts, cb) {
if (opts.conf.argv.remain.length > 2) return cb()
registry.get("/-/short", 60000, function (er, list) { registry.get("/-/short", 60000, function (er, list) {
return cb(null, list || []) return cb(null, list || [])
}) })
Expand All @@ -22,8 +21,20 @@ function url (json) {
} }


function docs (args, cb) { function docs (args, cb) {
var project = args[0] || '.' args = args || []
, package = path.resolve(process.cwd(), "package.json") var pending = args.length
if (!pending) return getDoc('.', cb)
args.forEach(function(proj) {
getDoc(proj, function(err) {
if (err) return cb(err)
--pending || cb()
})
})
}

function getDoc (project, cb) {
project = project || '.'
var package = path.resolve(process.cwd(), "package.json")


if (project === '.' || project === './') { if (project === '.' || project === './') {
try { try {
Expand Down

0 comments on commit 823010b

Please sign in to comment.