UNPKG

1.12 kBJavaScriptView Raw
1module.exports = stars
2
3stars.usage = 'npm stars [<user>]'
4
5var npm = require('./npm.js')
6var log = require('npmlog')
7var mapToRegistry = require('./utils/map-to-registry.js')
8var output = require('./utils/output.js')
9
10function stars (args, cb) {
11 npm.commands.whoami([], true, function (er, username) {
12 var name = args.length === 1 ? args[0] : username
13
14 if (er) {
15 if (er.code === 'ENEEDAUTH' && !name) {
16 var needAuth = new Error("'npm stars' on your own user account requires auth")
17 needAuth.code = 'ENEEDAUTH'
18 return cb(needAuth)
19 }
20
21 if (er.code !== 'ENEEDAUTH') return cb(er)
22 }
23
24 mapToRegistry('', npm.config, function (er, uri, auth) {
25 if (er) return cb(er)
26
27 var params = {
28 username: name,
29 auth: auth
30 }
31 npm.registry.stars(uri, params, showstars)
32 })
33 })
34
35 function showstars (er, data) {
36 if (er) return cb(er)
37
38 if (data.rows.length === 0) {
39 log.warn('stars', 'user has not starred any packages.')
40 } else {
41 data.rows.forEach(function (a) {
42 output(a.value)
43 })
44 }
45 cb()
46 }
47}