coming together
This commit is contained in:
Родитель
0f895e35e5
Коммит
1286434e23
|
@ -0,0 +1,61 @@
|
|||
const Report = require('./lib/report')
|
||||
const utils = require('./lib/utils')
|
||||
const {uniq, pick} = require('lodash')
|
||||
const repos = require('repos-using-electron').filter(repo => !repo.fork)
|
||||
const registry = require('all-the-packages')
|
||||
const Package = require('nice-package')
|
||||
const electronNpmPackages = require('electron-npm-packages')
|
||||
const MAX_RESULTS = 100
|
||||
const topDeps = utils.getTopDependencies(repos).slice(0, MAX_RESULTS)
|
||||
const topDevDeps = utils.getTopDevDependencies(repos).slice(0, MAX_RESULTS)
|
||||
const allPackageNames = uniq(topDeps.map(d => d.name).concat(topDevDeps.map(d => d.name)))
|
||||
|
||||
registry
|
||||
.on('package', function (pkg) {
|
||||
process.stdout.write('.')
|
||||
if (pkg && pkg.name && allPackageNames.includes(pkg.name)) {
|
||||
console.log(pkg.name)
|
||||
packageData[pkg.name] = new Package(pkg)
|
||||
}
|
||||
})
|
||||
.on('end', finish)
|
||||
|
||||
function finish () {
|
||||
// Add extra package metadata to dep lists
|
||||
topDeps.forEach(dep => Object.assign(dep, packageData[dep.name]) )
|
||||
topDevDeps.forEach(dep => Object.assign(dep, packageData[dep.name]) )
|
||||
|
||||
new Report({
|
||||
title: 'Top Dependencies in Apps',
|
||||
description: 'npm packages that are used most often as `dependencies` in Electron apps',
|
||||
collection: topDeps
|
||||
}).save()
|
||||
|
||||
new Report({
|
||||
title: 'Top Development Dependencies in Apps',
|
||||
description: 'npm packages that are used most often as `devDependencies` in Electron apps',
|
||||
collection: topDevDeps
|
||||
}).save()
|
||||
|
||||
new Report({
|
||||
title: 'Top GitHub Contributors',
|
||||
description: 'GitHub users that have contributed to the most Electron repositories',
|
||||
collection: utils.getTopContributors(repos).slice(0, MAX_RESULTS)
|
||||
}).save()
|
||||
|
||||
new Report({
|
||||
title: 'Electron-specific packages most-depended-on by other npm packages',
|
||||
description: 'Electron-specific npm packages that are depended on by other npm packages',
|
||||
collection: electronNpmPackages
|
||||
.sort((a, b) => b.totalDeps - a.totalDeps)
|
||||
.slice(0, MAX_RESULTS)
|
||||
}).save()
|
||||
|
||||
new Report({
|
||||
title: 'Most-downloaded Electron-specific npm Packages',
|
||||
description: 'Electron-specific npm packages that are depended on by other npm packages',
|
||||
collection: electronNpmPackages
|
||||
.sort((a, b) => b.downloadsInLastMonth - a.downloadsInLastMonth)
|
||||
.slice(0, MAX_RESULTS)
|
||||
}).save()
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
const validate = require('revalidator').validate
|
||||
const titlecase = require('ap-style-title-case')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = class Report {
|
||||
constructor (props) {
|
||||
|
@ -8,6 +9,10 @@ module.exports = class Report {
|
|||
return this
|
||||
}
|
||||
|
||||
get basename () {
|
||||
return this.title.toLowerCase().replace(/\s/g, '_')
|
||||
}
|
||||
|
||||
get valid () {
|
||||
return validate(this, schema).valid
|
||||
}
|
||||
|
@ -16,6 +21,14 @@ module.exports = class Report {
|
|||
return validate(this, schema).errors
|
||||
}
|
||||
|
||||
save () {
|
||||
if (!this.valid) return console.error(this.validationErrors)
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join((__dirname, `../reports/{this.basename}.json`)
|
||||
JSON.stringify(this, null, 2)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const schema = {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
const {compact, flatten} = require('lodash')
|
||||
const tally = require('count-array-values')
|
||||
const fetchPackage = require('fetch-nice-package')
|
||||
|
||||
function cleanNames (names) {
|
||||
return compact(flatten(names))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTopDependencies: (repos) => {
|
||||
const names = repos.map(repo => repo.pkg.depNames)
|
||||
return tally(cleanNames(names), 'name', 'dependents')
|
||||
},
|
||||
|
||||
getTopDevDependencies: (repos) => {
|
||||
const names = repos.map(repo => repo.pkg.devDepNames)
|
||||
return tally(cleanNames(names), 'name', 'devDependents')
|
||||
},
|
||||
|
||||
getTopContributors: (repos) => {
|
||||
const names = repos.map(repo => repo.contributors)
|
||||
return tally(cleanNames(names), 'user', 'repos')
|
||||
}
|
||||
}
|
13
package.json
13
package.json
|
@ -7,19 +7,30 @@
|
|||
"author": "zeke",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"all-the-packages": "^1.0.2",
|
||||
"ap-style-title-case": "^1.0.1",
|
||||
"chai": "^3.5.0",
|
||||
"count-array-values": "^1.2.1",
|
||||
"electron-npm-packages": "^2.0.3",
|
||||
"fetch-nice-package": "^1.0.2",
|
||||
"get-first-commit": "^0.2.0",
|
||||
"lodash": "^4.17.2",
|
||||
"mocha": "^3.2.0",
|
||||
"repos-using-electron": "^1.6.0",
|
||||
"nice-package": "^1.2.5",
|
||||
"repos-using-electron": "^1.9.0",
|
||||
"revalidator": "^0.3.1",
|
||||
"standard": "^8.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node bin/build.js",
|
||||
"test": "mocha && standard"
|
||||
},
|
||||
"standard": {
|
||||
"env": {
|
||||
"mocha": true
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче