Last active
February 18, 2016 22:13
-
-
Save timoxley/2351d5b709589c505fe9 to your computer and use it in GitHub Desktop.
find number of packages in still < 1.0.0 according to search cache
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
var columnify = require('columnify') | |
var fs = require('fs') | |
var results = []; | |
var packages = JSON.parse(fs.readFileSync(process.env.HOME + '/.npm/registry.npmjs.org/-/all/.cache.json')) | |
var packageNames = Object.keys(packages) | |
// only count packages with dist-tags + latest | |
var validPackages = packageNames.filter(function(name) { | |
var item = packages[name]; | |
return ( | |
item["dist-tags"] && | |
item["dist-tags"]["latest"] | |
) | |
}) | |
var counts = validPackages.reduce(function(counts, name) { | |
var major = parseInt(packages[name]["dist-tags"]["latest"].split('.')[0], 10) | |
counts[major] = counts[major] + 1 || 1 | |
return counts | |
}, {}) | |
var countsMeta = Object.keys(counts).map(function(major) { | |
return { | |
"major": major, | |
total: counts[major], | |
percent: (counts[major]/validPackages.length * 100).toFixed(2) + '%' | |
} | |
}) | |
console.log('') | |
console.log('Number of packages in the registry at particular major versions:') | |
console.log('') | |
console.log(columnify(countsMeta)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment