Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfosterelli committed Jul 7, 2016
0 parents commit 5873aa9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
43 changes: 43 additions & 0 deletions count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

/* Count
* Count the number of contributors a package has
*/

const axios = require('axios')
const _ = require('lodash')
const Promise = require('bluebird')
const ls = require('npm-remote-ls')

const npm = 'https://registry.npmjs.org/'

resolve(process.argv[2])
.then(count => console.log('Number of contribs:', count))
.catch(err => console.error(err))

function resolve(pckg) {
return new Promise((resolve, reject) => {
ls.ls(pckg, 'latest', true, list => {
const promises = []
list.forEach(pckg => {
promises.push(getContributors(pckg))
})
Promise.all(promises)
.then(sets => _.flatten(sets))
.then(flattened => _.uniq(flattened))
.then(contributors => contributors.length)
.then(count => resolve(count))
.catch(err => reject(err))
})
})
}

function getContributors(pckg) {
const url = npm + pckg.split('@')[0]
return axios.get(url)
.then(resp => {
const metadata = resp.data
const maintainers = metadata.maintainers
const users = maintainers.map(m => m.name)
return users
})
}

0 comments on commit 5873aa9

Please sign in to comment.