-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
27 lines (24 loc) · 946 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const requireDir = require('require-dir')
const path = require('path')
const fs = require('fs')
const blacklist = fs.readFileSync(path.join(__dirname, 'blacklist.txt'), 'utf8').split('\n')
const downloadCounts = require('download-counts')
const dependentCounts = require('dependent-counts')
const NicePackage = require('nice-package')
const packages = Object.values(requireDir('./packages'))
.filter(pkg => !blacklist.includes(pkg.name))
.map(pkg => {
pkg = Object.assign(pkg, {
averageDailyDownloads: getAverageDailyDownloads(pkg),
dependentCounts: getDependentCounts(pkg)
})
return new NicePackage(pkg)
})
.sort((a, b) => b.averageDailyDownloads - a.averageDailyDownloads)
module.exports = packages
function getAverageDailyDownloads (pkg) {
return downloadCounts[pkg.name] || 0
}
function getDependentCounts (pkg) {
return dependentCounts.find(dep => dep.name === pkg.name) || {totalDirectDependents: 0}
}