tests, reports, downloads oh my

This commit is contained in:
Zeke Sikelianos 2016-11-12 20:29:34 -08:00
Родитель 65a71f4ef7
Коммит 4b3facda52
9 изменённых файлов: 48 добавлений и 25 удалений

Просмотреть файл

@ -8,7 +8,7 @@ registry
if (pkg.valid && pkg.mentions('electron') && !pkg.mentions('electronic')) {
console.log(pkg.name)
fs.writeFileSync(
path.join(__dirname, 'packages', `${pkg.name}.json`),
path.join(__dirname, '../packages', `${pkg.name}.json`),
JSON.stringify(pkg, null, 2)
)
}

Просмотреть файл

@ -2,11 +2,11 @@ const got = require('got')
const fs = require('fs')
const path = require('path')
const exists = require('path-exists').sync
const packageNames = require('.').map(p => p.name)
const packageNames = require('..').map(p => p.name)
const RateLimiter = require('limiter').RateLimiter
const limiter = new RateLimiter(1, 1000)
function getDownloadCount(pkg, callback) {
function getDownloadCount (pkg, callback) {
const url = `https://api.npmjs.org/downloads/point/last-month/${pkg}`
got(url)
.then(result => { callback(null, JSON.parse(result.body).downloads) })
@ -14,12 +14,13 @@ function getDownloadCount(pkg, callback) {
}
packageNames
.filter(name => !exists(path.join(__dirname, `./downloads/${name}.json`)))
.filter(name => !exists(path.join(__dirname, `../downloads/${name}.json`)))
.forEach(name => {
limiter.removeTokens(1, function() {
getDownloadCount(name, function(err, count) {
limiter.removeTokens(1, function () {
getDownloadCount(name, function (err, count) {
if (err) return console.error(err)
console.log(`${name}: ${count}`)
fs.writeFileSync(path.join(__dirname, `./downloads/${name}.json`), String(count))
fs.writeFileSync(path.join(__dirname, `../downloads/${name}.json`), String(count))
})
})
})
})

Просмотреть файл

@ -3,16 +3,20 @@ const path = require('path')
const objectValues = require('object-values')
const requireDir = require('require-dir')
const exists = require('path-exists').sync
const dependents = require('dependent-packages')
const Package = require('nice-package')
var packages = objectValues(requireDir('./packages')).map(pkg => {
return new Package(pkg)
})
const cleanDeep = require('clean-deep')
var packages = objectValues(requireDir('./packages')).map(pkgData => {
var pkg = new Package(pkgData)
packages.forEach(p => {
var file = path.join(__dirname, `./downloads/${p.name}.json`)
if (exists(file)) {
p.downloadsInLastMonth = Number(fs.readFileSync(file, 'utf8'))
}
var file = path.join(__dirname, `downloads/${pkg.name}.json`)
if (exists(file)) pkg.downloadsInLastMonth = Number(fs.readFileSync(file, 'utf8'))
pkg.dependents = dependents.dependentsOf(pkg.name) || []
pkg.devDependents = dependents.devDependentsOf(pkg.name) || []
return pkg
})
.sort((a, b) => b.dependents.length - a.dependents.length)
module.exports = packages

Просмотреть файл

@ -5,9 +5,11 @@
"main": "index.js",
"scripts": {
"build": "mkdir -p packages && touch packages/___.json && rm packages/* && node build.js && npm run docs",
"docs": "npm run docs:keywords && npm run docs:packages",
"docs:keywords": "node keywords.js > keywords.md",
"docs:packages": "node packages.js > packages.md"
"build:downloads": "node bin/downloads.js",
"reports": "npm-run-all reports*",
"reports:keywords": "node reports/keywords.js > reports/keywords.md",
"reports:packages": "node reports/packages.js > reports/packages.md",
"test": "node test.js | tap-spec && standard"
},
"repository": "https://github.com/zeke/electron-npm-packages",
"keywords": [
@ -27,13 +29,19 @@
},
"homepage": "https://github.com/zeke/electron-npm-packages#readme",
"devDependencies": {
"dependent-packages": "^1.0.0",
"got": "^6.3.0",
"limiter": "^1.1.0",
"lodash.find": "^4.4.0",
"lodash.sortby": "^4.5.0",
"path-exists": "^3.0.0"
"npm-run-all": "^3.1.1",
"path-exists": "^3.0.0",
"standard": "^8.5.0",
"tap-spec": "^4.1.1",
"tape": "^4.6.2"
},
"dependencies": {
"clean-deep": "^2.0.1",
"limiter": "^1.1.0",
"nice-package": "^1.0.5",
"object-values": "^1.0.0",

Просмотреть файл

@ -11,16 +11,16 @@ packages.forEach(p => {
if (count) {
count.count += 1
} else {
counts.push({keyword: keyword, count:1})
counts.push({keyword: keyword, count: 1})
}
})
})
counts = sortby(counts, 'count').reverse()
counts.forEach(count => {
var keyword = count.keyword
var count = count.count
counts.forEach(c => {
var keyword = c.keyword
var count = c.count
if (keyword.toLowerCase() === 'electron') return
console.log(`\n\n### ${keyword} (${count})\n\n`)
@ -32,5 +32,4 @@ counts.forEach(count => {
.forEach(p => {
console.log(`- [${p.name}](http://npm.im/${p.name}) - ${p.description}`)
})
})

Просмотреть файл

Просмотреть файл

Просмотреть файл

11
test.js Normal file
Просмотреть файл

@ -0,0 +1,11 @@
const test = require('tape')
const packages = require('.')
test('packages', function (t) {
t.ok(Array.isArray(packages), 'is an array')
t.ok(packages.length > 1600, 'has lots of packages')
const electronIsDev = packages.find(p => p.name === 'electron-is-dev')
t.ok(electronIsDev.dependents.length > 3, 'packages have arrays of dependents')
t.end()
})