forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.js
41 lines (37 loc) · 1.04 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = docs
var openUrl = require('./utils/open-url')
var log = require('npmlog')
var fetchPackageMetadata = require('./fetch-package-metadata.js')
var usage = require('./utils/usage')
docs.usage = usage(
'docs',
'npm docs <pkgname>' +
'\nnpm docs .'
)
docs.completion = function (opts, cb) {
// FIXME: there used to be registry completion here, but it stopped making
// sense somewhere around 50,000 packages on the registry
cb()
}
function docs (args, cb) {
if (!args || !args.length) args = ['.']
var pending = args.length
log.silly('docs', args)
args.forEach(function (proj) {
getDoc(proj, function (err) {
if (err) {
return cb(err)
}
--pending || cb()
})
})
}
function getDoc (project, cb) {
log.silly('getDoc', project)
fetchPackageMetadata(project, '.', {fullMetadata: true}, function (er, d) {
if (er) return cb(er)
var url = d.homepage
if (!url) url = 'https://www.npmjs.org/package/' + d.name
return openUrl(url, 'docs available at the following URL', cb)
})
}