Benjamin Lannon

Benjamin Lannon

// Menu: GitHub Trending
// Description: Show today's Trending GitHub Repos for various languages
const trendingDB = db("github-trending");
const langs = ["rust", "javascript", "typescript", "go", "python", "ruby"];
for (const lang of langs) {
onTab(lang, async () => {
const repo = await arg("Select a repo to open it", trendingDB.get(lang));
exec(`open ${repo}`);
});
}
// Description: Pulls down trending repos from github and save to database
// Schedule: 0 * * * *
// Exclude: true
/** @type typeof import('playwright') */
const playwright = await npm("playwright");
let dbDefaults = {};
const langs = ["rust", "javascript", "typescript", "go", "python", "ruby"];
for (const lang of langs) {
dbDefaults[lang] = [];
}
const trendingDB = db("github-trending", dbDefaults);
const browser = await playwright.chromium.launch();
for (const lang of langs) {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(`https://github.com/trending/${lang}`);
const repos = await page.evaluate(() => {
const repos = document.querySelectorAll(".Box-row");
const results = [];
for (let repo of repos) {
const repoName = repo.querySelector("h1 a").getAttribute("href").slice(1);
let description = repo.querySelector("p")?.textContent.trim();
const starCount = repo
.querySelector("div span.d-inline-block.float-sm-right")
?.textContent.trim();
if (!description) {
description = starCount;
} else {
description = `${starCount} | ${description}`;
}
results.push({
name: repoName,
value: `https://github.com/${repoName}`,
description,
});
}
return results;
});
trendingDB.set(lang, repos).write();
}
await browser.close();

// Menu: Available Node versions
// Description: View all supported versions of NodeJS
// Author: Benjamin Lannon
// Twitter: @lannonbr
let resp = await get(
"https://raw.githubusercontent.com/nodejs/Release/main/schedule.json"
);
const data = Object.entries(resp.data);
/** @type typeof import('dayjs') */
let dayjs = await npm("dayjs");
let opts = [];
for (let [version, info] of data) {
let isSupported =
dayjs(info.start).diff(dayjs(), "days") < 0 &&
dayjs(info.end).diff(dayjs(), "days") > 0;
if (isSupported) {
opts.push({
name: `Node ${version}`,
description: `Maintainence ends on ${dayjs(info.end).format(
"MMMM DD, YYYY"
)}`,
endDate: info.end,
});
}
}
opts = opts.sort((a, b) => {
return dayjs(a.endDate).unix() - dayjs(b.endDate).unix();
});
await arg("These versions of NodeJS are currently maintained", opts);