-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
73 lines (59 loc) · 2.36 KB
/
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
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const outputToCSV = require('./outputs/csv');
const packageDownloads = require('./src/package-downloads');
const packageMetadata = require('./src/packument-metadata');
function parseModuleType(type) {
// Figure out if this is an ESM or CJS module or both
// TODO: figure out logic for both and how to check if it is an .mjs
if (type === 'module') {
return 'ESM';
}
return 'CJS';
}
function parseRepository(repository) {
// Find the source control link
// TODO: Should be more better than this
return repository.url;
}
async function run() {
// Get the list of modules from the reference architecture repo
// https://raw.githubusercontent.com/nodeshift/nodejs-reference-architecture/main/npcheck.json
const response = await fetch('https://raw.githubusercontent.com/nodeshift/nodejs-reference-architecture/main/npcheck.json');
const refArchModules = await response.json();
// Get the downloads for the module list
const moduleDownloads = await packageDownloads(refArchModules.modules);
// Get the pacakge metadata for the module list
const packageMetadatas = await packageMetadata(refArchModules.modules);
const mapped = packageMetadatas.map((obj) => {
// based on the object _id, find the package in the downloads array and add it to this obj and return
const foundDownloadStat = moduleDownloads.find((stat) => {
return obj._id === stat.package;
});
// Need to only provide the stuff we need
const latestVersion = obj['dist-tags'].latest;
const latestVersionInfo = obj.versions[latestVersion];
return {
name: obj.name,
reviewlevel: obj.reviewlevel,
activitycurrent: obj.activitycurrent,
activitytarget: obj.activitytarget,
foundation: obj.foundation,
section: obj.section,
npmlink: obj.npmlink || obj.npmLink,
description: obj.description,
modified: obj.time.modified,
type: parseModuleType(latestVersionInfo.type),
repository: parseRepository(obj.repository),
latestVersion,
latestVersionInfo,
...foundDownloadStat
};
});
// output the list
// mapped.forEach((val) => {
// console.log(val);
// // console.log(`Package: ${val.name} Downloads: ${val.downloads} Description: ${val.description} Latest: ${val.latestVersion} Module type: ${val.type} Modified: ${val.modified}`);
// })
outputToCSV(mapped);
}
run();