-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpmsstats.js
52 lines (49 loc) · 2.25 KB
/
npmsstats.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const process = require('process');
const http = require('./http.js').http;
const config = require('./config.json');
async function analyzeRepo(name, repo) {
return new Promise(async (resolve) => {
const data = await http(`https://api.npms.io/v2/package/${name.replace('/', '%2F')}`);
resolve({
name: repo?.package?.name || data.collected.metadata.name,
version: repo?.package?.version || data.collected.metadata.version,
// date: new Date(repo?.package?.date || data.collected.metadata.date),
analyzed: new Date(data.analyzedAt),
score: Math.round(100 * (repo?.score?.final || data.score.final)),
quality: {
score: Math.round(100 * (repo?.score?.detail?.quality || data.score.detail.quality)),
carefulness: Math.round(100 * data.evaluation?.quality.carefulness),
tests: Math.round(100 * data.evaluation?.quality.tests),
health: Math.round(100 * data.evaluation?.quality.health),
branding: Math.round(100 * data.evaluation?.quality.branding),
},
popularity: {
score: Math.round(100 * (repo?.score?.detail?.popularity || data.score.detail.popularity)),
community: data.evaluation.popularity.communityInterest,
dl: Math.round(data.evaluation.popularity.downloadsCount),
accel: Math.round(100 * data.evaluation.popularity.downloadsAcceleration) / 100,
},
maintenance: {
score: Math.round(100 * (repo?.score?.detail?.maintenance || data.score.detail.maintenance)),
releases: Math.round(100 * data.evaluation.maintenance.releasesFrequency),
commits: Math.round(100 * data.evaluation.maintenance.commitsFrequency),
issues: Math.round(100 * data.evaluation.maintenance.issuesDistribution),
},
search: Math.round(100 * repo?.searchScore),
});
});
}
async function npmsRepositories() {
const res = await http(`https://api.npms.io/v2/search?q=${config.npmjs.user}`);
let repos = [];
if (res && res.results) {
for (const repo of res.results) {
if (repo.package?.author?.username !== config.npmjs.user) continue
const data = analyzeRepo(repo.package.name, repo);
repos.push(data);
}
}
repos = await Promise.all(repos);
return repos;
}
exports.npmsRepositories = npmsRepositories;