-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5873aa9
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |