Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloads most popular lodash dependents
const axios = require('axios');
const cheerio = require('cheerio');
const childProcess = require('child_process');
(async () => {
const {data: npmListHtml} = await axios.get('https://www.npmjs.com/browse/depended/lodash');
const $ = cheerio.load(npmListHtml);
const npmPackageLinks = $('section a').map((i, elem) => $(elem).attr('href')).get();
childProcess.execSync(`rm -rf ${__dirname}/packages`);
childProcess.execSync(`mkdir ${__dirname}/packages`);
for (const npmPackageLink of npmPackageLinks) {
console.log(`Loading NPM page ${npmPackageLink}`)
const {data: npmPackageHtml} = await axios.get(`https://www.npmjs.com/${npmPackageLink}`);
const $ = cheerio.load(npmPackageHtml);
const gitHubUrl = $('a.link.truncate').last().attr('href');
try {
console.log(`Cloning ${gitHubUrl}`);
childProcess.execSync(`git -C ${__dirname}/packages clone ${gitHubUrl}`);
} catch (e) {
console.log(`Can't clone ${gitHubUrl}`)
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment