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