1 | 'use strict'
|
2 |
|
3 | const BB = require('bluebird')
|
4 |
|
5 | const npmConfig = require('./config/figgy-config.js')
|
6 | const fetch = require('libnpm/fetch')
|
7 | const log = require('npmlog')
|
8 | const output = require('./utils/output.js')
|
9 | const whoami = require('./whoami.js')
|
10 |
|
11 | stars.usage = 'npm stars [<user>]'
|
12 |
|
13 | module.exports = stars
|
14 | function stars ([user], cb) {
|
15 | const opts = npmConfig()
|
16 | return BB.try(() => {
|
17 | return (user ? BB.resolve(user) : whoami([], true, () => {})).then(usr => {
|
18 | return fetch.json('/-/_view/starredByUser', opts.concat({
|
19 | query: {key: `"${usr}"`}
|
20 | }))
|
21 | }).then(data => data.rows).then(stars => {
|
22 | if (stars.length === 0) {
|
23 | log.warn('stars', 'user has not starred any packages.')
|
24 | } else {
|
25 | stars.forEach(s => output(s.value))
|
26 | }
|
27 | })
|
28 | }).catch(err => {
|
29 | if (err.code === 'ENEEDAUTH') {
|
30 | throw Object.assign(new Error("'npm stars' on your own user account requires auth"), {
|
31 | code: 'ENEEDAUTH'
|
32 | })
|
33 | } else {
|
34 | throw err
|
35 | }
|
36 | }).nodeify(cb)
|
37 | }
|