Skip to content

Instantly share code, notes, and snippets.

@alexey-detr
Created September 1, 2018 08:31
Show Gist options
  • Save alexey-detr/3e316f95793a1c80843480be15535608 to your computer and use it in GitHub Desktop.
Save alexey-detr/3e316f95793a1c80843480be15535608 to your computer and use it in GitHub Desktop.
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