Skip to content

Commit

Permalink
star: stop using npm-registry-client
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jul 27, 2018
1 parent 7047ffd commit 11c07b3
Showing 1 changed file with 51 additions and 25 deletions.
76 changes: 51 additions & 25 deletions lib/star.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module.exports = star
'use strict'

const BB = require('bluebird')

var npm = require('./npm.js')
var log = require('npmlog')
var asyncMap = require('slide').asyncMap
var mapToRegistry = require('./utils/map-to-registry.js')
var usage = require('./utils/usage')
var output = require('./utils/output.js')
const config = require('./config/figgy-config.js')
const fetch = require('npm-registry-fetch')
const log = require('npmlog')
const npa = require('npm-package-arg')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const usage = require('./utils/usage.js')
const whoami = require('./whoami.js')

star.usage = usage(
'star',
Expand All @@ -19,27 +23,49 @@ star.completion = function (opts, cb) {
cb()
}

module.exports = star
function star (args, cb) {
if (!args.length) return cb(star.usage)
var s = npm.config.get('unicode') ? '\u2605 ' : '(*)'
var u = npm.config.get('unicode') ? '\u2606 ' : '( )'
var using = !(npm.command.match(/^un/))
if (!using) s = u
asyncMap(args, function (pkg, cb) {
mapToRegistry(pkg, npm.config, function (er, uri, auth) {
if (er) return cb(er)
return BB.try(() => {
if (!args.length) throw new Error(star.usage)
let s = npm.config.get('unicode') ? '\u2605 ' : '(*)'
const u = npm.config.get('unicode') ? '\u2606 ' : '( )'
const using = !(npm.command.match(/^un/))
if (!using) s = u
return BB.map(args.map(npa), pkg => {
return BB.all([
whoami([pkg], true, () => {}),
fetch.json(pkg.escapedName, config({
spec: pkg,
query: {write: true},
'prefer-online': true
}))
]).then(([username, fullData]) => {
if (!username) { throw new Error('You need to be logged in!') }
const body = {
_id: fullData._id,
_rev: fullData._rev,
users: fullData.users || {}
}

var params = {
starred: using,
auth: auth
}
npm.registry.star(uri, params, function (er, data, raw, req) {
if (!er) {
output(s + ' ' + pkg)
log.verbose('star', data)
if (using) {
log.info('star', 'starring', body._id)
body.users[username] = true
log.verbose('star', 'starring', body)
} else {
delete body.users[username]
log.info('star', 'unstarring', body._id)
log.verbose('star', 'unstarring', body)
}
cb(er, data, raw, req)
return fetch.json(pkg.escapedName, config({
spec: pkg,
method: 'PUT',
body
}))
}).then(data => {
output(s + ' ' + pkg.name)
log.verbose('star', data)
return data
})
})
}, cb)
}).nodeify(cb)
}

0 comments on commit 11c07b3

Please sign in to comment.