Created
March 23, 2016 14:03
-
-
Save jackwanders/9e7def8bb5b54540c125 to your computer and use it in GitHub Desktop.
Script used to determine current publish status of azer's packages. Done out of curiosity as to who is claiming the free'd up npm package names.
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
'use strict'; | |
let _ = require('lodash'); | |
let Promise = require('bluebird'); | |
let request = Promise.promisify(require('request')); | |
let pkg_list = 'https://gist.githubusercontent.com/azer/db27417ee84b5f34a6ea/raw/50ab7ef26dbde2d4ea52318a3590af78b2a21162/gistfile1.txt'; | |
let registry = 'http://registry.npmjs.org/'; | |
function processPkgs(pkgs) { | |
let data = { | |
maintainerCounts: [], | |
unpublished: [], | |
published: [] | |
}; | |
pkgs.forEach(pkg => { | |
let info = getInfo(pkg); | |
data[info.version ? 'published' : 'unpublished'].push(info); | |
}); | |
data.published = _(data.published) | |
.groupBy('maintainers') | |
.forEach((publishedPkgs, maintainer) => { | |
publishedPkgs = _.sortBy(publishedPkgs, 'publishTime'); | |
data.maintainerCounts.push({ | |
maintainer: maintainer, | |
count: publishedPkgs.length | |
}); | |
}); | |
data.maintainerCounts = _.sortBy(data.maintainerCounts, 'count').reverse(); | |
return data; | |
} | |
function getInfo(pkg) { | |
let unpublished = pkg.time.unpublished; | |
let latest = pkg['dist-tags'] && pkg['dist-tags'].latest; | |
let lastPublish = latest && pkg.time[latest] && new Date(pkg.time[latest]); | |
if (unpublished) { | |
return { | |
pkg: pkg.name, | |
at: unpublished.time, | |
by: unpublished.name | |
}; | |
} else { | |
return { | |
pkg: pkg.name, | |
version: pkg['dist-tags'].latest, | |
publishTime: lastPublish, | |
maintainers: pkg.maintainers && pkg.maintainers.map(m => m.name).join(', '), | |
author: pkg.author && pkg.author.name | |
}; | |
} | |
} | |
request(pkg_list) | |
.then(res => res.body.split('\n')) | |
.then(pkgs => pkgs.map(pkg => request(registry + pkg))) | |
.all() | |
.then(ress => ress.map(res => JSON.parse(res.body))) | |
.then(processPkgs) | |
.then(data => console.log(JSON.stringify(data, null, '\t'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment