2022-12-25 12:48:18 -05:00
|
|
|
import fs from 'fs/promises';
|
|
|
|
import got from 'got';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const data = require('../website/src/components/EcosystemSearch/addons.json');
|
|
|
|
for (let item of data.addons) {
|
|
|
|
try {
|
|
|
|
const d = await got(`https://registry.npmjs.org/${item.name}`).json();
|
|
|
|
const apiDownloads = await got(
|
|
|
|
`https://api.npmjs.org/downloads/point/last-month/${item.name}`
|
|
|
|
).json();
|
|
|
|
// @ts-ignore
|
|
|
|
item.description = d.description;
|
2023-12-20 15:32:58 -05:00
|
|
|
// remove html tags from description (e.g. <h1...>)
|
2023-12-24 14:45:09 -05:00
|
|
|
// CodeQL js/incomplete-multi-character-sanitization
|
|
|
|
let previous;
|
|
|
|
do {
|
|
|
|
previous = item.description;
|
|
|
|
item.description = item.description.replace(/<[^>]*>?/gm, '');
|
|
|
|
} while (item.description !== previous);
|
2023-12-20 15:32:58 -05:00
|
|
|
// remove markdown links from description (e.g. [link](url))
|
2023-12-24 14:45:09 -05:00
|
|
|
item.description = item.description.trim().replace(/\[(.*?)\]\(.*?\)/gm, '$1');
|
2022-12-25 12:48:18 -05:00
|
|
|
item.url = `https://www.npmjs.org/${item.name}`;
|
|
|
|
item.registry = `https://registry.npmjs.org/${item.name}`;
|
|
|
|
item.bundled = typeof item.bundled === 'boolean' ? item.bundled : false;
|
|
|
|
item.origin = item.origin ? item.origin : 'community';
|
|
|
|
item.category = item.category ? item.category : 'authentication';
|
|
|
|
// @ts-ignore
|
|
|
|
item.latest = d['dist-tags'].latest;
|
|
|
|
// @ts-ignore
|
|
|
|
item.downloads = apiDownloads.downloads;
|
|
|
|
// console.log('d', item);
|
|
|
|
} catch (err) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error('error for %s', item.name, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await fs.writeFile(
|
|
|
|
path.join(__dirname, '../website/src/components/EcosystemSearch/addons.json'),
|
|
|
|
JSON.stringify({ ...data }, null, 4)
|
|
|
|
);
|
|
|
|
})();
|