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
|
module.exports = docs
docs.usage = "npm docs <pkgname>"
docs.completion = function (opts, cb) {
if (opts.conf.argv.remain.length > 2) return cb()
registry.get("/-/short", 60000, function (er, list) {
return cb(null, list || [])
})
}
var npm = require("./npm.js")
, registry = npm.registry
, log = require("npmlog")
, opener = require("opener")
function docs (args, cb) {
if (!args.length) return cb(docs.usage)
var project = args[0]
var npmName = project.split("@").shift()
registry.get(project + "/latest", 3600, function (er, d) {
if (er) {
if (project.split("/").length !== 2) return cb(er)
var url = "https://github.com/" + project + "#readme"
return opener(url, { command: npm.config.get("browser") }, cb)
}
var homepage = d.homepage
, repo = d.repository || d.repositories
, url = homepage ? homepage
: "https://npmjs.org/package/" + d.name
opener(url, { command: npm.config.get("browser") }, cb)
})
}
|