Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Last active November 7, 2023 01:36
Show Gist options
  • Save SgtPooki/125b0f30d12bc19fc799e78c317955e1 to your computer and use it in GitHub Desktop.
Save SgtPooki/125b0f30d12bc19fc799e78c317955e1 to your computer and use it in GitHub Desktop.
This script requires a markdown table for input, as generated by https://github.com/nvuillam/github-dependents-info. It compares the current table with the previous one and outputs a new table with the changes in stars.
#!/usr/bin/env node
/**
* This script requires a markdown table for input, as generated by https://github.com/nvuillam/github-dependents-info
* It compares the current table with the previous one and outputs a new table with the changes in stars.
* Usage:
* github-dependents-info --repo ipfs/helia --markdownfile ./package-usage-2023-09.md --sort stars --verbose -x 2 -p
* // manually copy the Repostory and Stars table to `current.md`
* // manually copy the Repostory and Stars table from the previous month to `previous.md`
* node dependents-change.js
*
* This is used to generate the table in Helia reports, like at https://pl-strflt.notion.site/Helia-Report-2023-09-892d8510e49549b6b96fd87323c0c715#2b2d82cd734e45fab4c6b6549cb06e2c
*/
import fs from 'node:fs'
// read the previous table from `previous.md`
const previousMonthTable = fs.readFileSync('previous.md', 'utf8');
const currentMonthTable = fs.readFileSync('current.md', 'utf8');
// Function to parse a Markdown table and create an object
function parseMarkdownTable(table) {
const lines = table.trim().split('\n');
const header = lines[1].split('|').map(cell => cell.trim()).filter(Boolean);
const data = {};
for (let i = 2; i < lines.length; i++) {
const row = lines[i].split('|').map(cell => cell.trim()).filter(Boolean);
if (row.length === header.length) {
data[row[0].toLowerCase()] = parseInt(row[1].toLowerCase());
}
}
// make sure all keys are github urls only so we can compare them correctly.
// i.e. convert from something like `[linkName](url)` to just `url`
for (const key in data) {
const match = key.match(/\[.*\]\((.*)\)/);
if (match) {
data[match[1]] = data[key];
delete data[key];
}
}
return data;
}
// Parse the tables and create objects
const previousMonthData = parseMarkdownTable(previousMonthTable);
const currentMonthData = parseMarkdownTable(currentMonthTable);
// Find new repositories and changes in stars
const changesInStars = {};
for (const repository in previousMonthData) {
if (repository in currentMonthData) {
const starChange = currentMonthData[repository] - previousMonthData[repository];
changesInStars[repository] = starChange;
}
}
// Prepare and log the result in Markdown format with clickable links
console.log('| Repository | Stars | Change |');
console.log('| --- | --- | --- |');
for (const repository in currentMonthData) {
const starsCurrent = currentMonthData[repository];
const change = changesInStars[repository] ?? 'NEW';
const repoName = repository.replace('https://github.com/', '').replace('/', '/');
const repoLink = `[${repoName}](${repository})`;
console.log(`| ${repoLink} | ${starsCurrent} | ${change} |`);
}
{
"name": "@SgtPooki/dependents-change",
"version": "1.0.1",
"bin": "./dependents-change.js",
"type": "module"
}
@SgtPooki
Copy link
Author

SgtPooki commented Nov 7, 2023

October report current.md output:

| Repository | Stars  |
| :--------  | -----: |
|[ipfs/ipfs-webui](https://github.com/ipfs/ipfs-webui) | 1477 |
|[ipfs/helia](https://github.com/ipfs/helia) | 532 |
|[yazz/yazz](https://github.com/yazz/yazz) | 519 |
|[cyph/cyph](https://github.com/cyph/cyph) | 365 |
|[ipld/explore.ipld.io](https://github.com/ipld/explore.ipld.io) | 112 |
|[darrylyeo/blockhead](https://github.com/darrylyeo/blockhead) | 84 |
|[ipfs/js-datastore-s3](https://github.com/ipfs/js-datastore-s3) | 72 |
|[usecannon/cannon](https://github.com/usecannon/cannon) | 67 |
|[iohzrd/identia](https://github.com/iohzrd/identia) | 65 |
|[pinnacle-labs/taqueria](https://github.com/pinnacle-labs/taqueria) | 62 |
|[LibertyDSNP/frequency](https://github.com/LibertyDSNP/frequency) | 43 |
|[ipfs-examples/helia-examples](https://github.com/ipfs-examples/helia-examples) | 33 |
|[hldb/welo](https://github.com/hldb/welo) | 26 |
|[orochi-network/zkDatabase](https://github.com/orochi-network/zkDatabase) | 25 |
|[ipfs/ipld-explorer-components](https://github.com/ipfs/ipld-explorer-components) | 23 |
|[sanchezcarlosjr/evanotebook](https://github.com/sanchezcarlosjr/evanotebook) | 14 |
|[tabcat/dynamic-content](https://github.com/tabcat/dynamic-content) | 14 |
|[yayacat/TREM](https://github.com/yayacat/TREM) | 13 |
|[ipfs/js-stores](https://github.com/ipfs/js-stores) | 13 |
|[sunodo/sunodo](https://github.com/sunodo/sunodo) | 11 |
|[tabcat/zzzync](https://github.com/tabcat/zzzync) | 11 |
|[ipfs/helia-unixfs](https://github.com/ipfs/helia-unixfs) | 11 |
|[esdt-space/mx-dapp-template](https://github.com/esdt-space/mx-dapp-template) | 9 |
|[HybridWare/zero-browser](https://github.com/HybridWare/zero-browser) | 8 |
|[polus-arcticus/obsidian-lilypad](https://github.com/polus-arcticus/obsidian-lilypad) | 8 |
|[ipfs-shipyard/helia-service-worker-gateway](https://github.com/ipfs-shipyard/helia-service-worker-gateway) | 7 |
|[ipfs/helia-ipns](https://github.com/ipfs/helia-ipns) | 7 |
|[Permissionless-Software-Foundation/ipfs-service-provider](https://github.com/Permissionless-Software-Foundation/ipfs-service-provider) | 6 |
|[BigDog1400/code0](https://github.com/BigDog1400/code0) | 6 |
|[scobru/mecenate-monorepo](https://github.com/scobru/mecenate-monorepo) | 6 |
|[carllippert/SecretAgents](https://github.com/carllippert/SecretAgents) | 6 |
|[vmx/colleemap](https://github.com/vmx/colleemap) | 5 |
|[mbcse/web3stash](https://github.com/mbcse/web3stash) | 5 |
|[ipfs/helia-json](https://github.com/ipfs/helia-json) | 5 |
|[SgtPooki/helia-playground](https://github.com/SgtPooki/helia-playground) | 4 |
|[ansi-code/ipdw](https://github.com/ansi-code/ipdw) | 4 |
|[ipfs/helia-car](https://github.com/ipfs/helia-car) | 4 |
|[ipfs/helia-dag-cbor](https://github.com/ipfs/helia-dag-cbor) | 4 |
|[ipfs/helia-strings](https://github.com/ipfs/helia-strings) | 4 |
|[aspiringsecurity/EMTTR](https://github.com/aspiringsecurity/EMTTR) | 3 |
|[botfi-app/botfi-wallet](https://github.com/botfi-app/botfi-wallet) | 3 |
|[ipfs-shipyard/www-helia-identify](https://github.com/ipfs-shipyard/www-helia-identify) | 3 |
|[ipfs/helia-mfs](https://github.com/ipfs/helia-mfs) | 3 |
|[face-protocol/app](https://github.com/face-protocol/app) | 3 |
|[ocdbytes/IPFS_DUMP_REPO](https://github.com/ocdbytes/IPFS_DUMP_REPO) | 3 |
|[hldb/todomvc](https://github.com/hldb/todomvc) | 3 |
|[ipfs/helia-dag-json](https://github.com/ipfs/helia-dag-json) | 3 |
|[nftstudio-24/nftstudio24-ICP](https://github.com/nftstudio-24/nftstudio24-ICP) | 2 |
|[noryev/LargeFieldDataAnalyzer](https://github.com/noryev/LargeFieldDataAnalyzer) | 2 |
|[Obsidian-Desci/Obsidian-Desci](https://github.com/Obsidian-Desci/Obsidian-Desci) | 2 |
|[ipfs-shipyard/www-helia-io](https://github.com/ipfs-shipyard/www-helia-io) | 2 |
|[ipfs/helia-http-gateway](https://github.com/ipfs/helia-http-gateway) | 2 |
|[ronykris/dapilink](https://github.com/ronykris/dapilink) | 2 |
|[polus-arcticus/helia-pubsub-webrtc](https://github.com/polus-arcticus/helia-pubsub-webrtc) | 2 |
|[NAKITARE00/ETHSAFARIDAOMEDYAPP](https://github.com/NAKITARE00/ETHSAFARIDAOMEDYAPP) | 2 |
|[avasdao/nexa-garden](https://github.com/avasdao/nexa-garden) | 2 |
|[danimbrogno/union-dao](https://github.com/danimbrogno/union-dao) | 2 |
|[magomedov-b/bashir_nft_marketplace](https://github.com/magomedov-b/bashir_nft_marketplace) | 2 |
|[programmeruser2/Cosmic](https://github.com/programmeruser2/Cosmic) | 2 |
|[awesome-abstraction/waas-pay](https://github.com/awesome-abstraction/waas-pay) | 2 |
|[open-predict/OpenPredict](https://github.com/open-predict/OpenPredict) | 2 |
|[arosboro/newsletter-fe](https://github.com/arosboro/newsletter-fe) | 2 |
|[frontline-hq/web3db](https://github.com/frontline-hq/web3db) | 2 |
|[subvisual/CosmicWave-fe](https://github.com/subvisual/CosmicWave-fe) | 2 |
|[md0x/defikicks](https://github.com/md0x/defikicks) | 2 |
|[HomoSimulo/NFT-TD](https://github.com/HomoSimulo/NFT-TD) | 2 |
|[mmsaki/star-streamer](https://github.com/mmsaki/star-streamer) | 2 |
|[SgtPooki/helia-service-worker-gateway](https://github.com/SgtPooki/helia-service-worker-gateway) | 2 |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment