Files
antigravity-awesome-skills/tools/scripts/sync-readme-stats.js
Emanoel Carvalho f61417a2e0 Automate README Skill Count Sync from /skills (#532)
* feat(skill): Added a skill for agents understand how then can work with mise-en-place

* Update related skills in SKILL.md

* fix(skill): Make mise configurator deterministic

* chore(package): add a npm run command, to sync skills of automatic maner on README.md

* feat(tool): add a new tool script to count and replace number of script on README.md

* refactor(method): adjusted method to grant a return

---------

Co-authored-by: sickn33 <sickn33@users.noreply.github.com>
2026-04-20 19:41:39 +02:00

108 lines
2.3 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const ROOT = path.resolve(__dirname, "../../");
const README_PATH = path.join(ROOT, "README.md");
const SKILLS_DIR = path.join(ROOT, "skills");
function countSkills(dir) {
let total = 0;
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const skillFile = path.join(fullPath, "SKILL.md");
if (fs.existsSync(skillFile)) {
total++;
}
total += countSkills(fullPath);
}
}
return total;
}
function formatNumber(n) {
return n.toLocaleString("en-US");
}
function replaceOrWarn(content, regex, replacement, label) {
const safeRegex = new RegExp(regex.source, regex.flags.replace("g", ""));
const hasMatch = safeRegex.test(content);
if (!hasMatch) {
console.warn(`⚠️ Pattern not found: ${label}`);
return content;
}
return content.replace(regex, replacement);
}
if (!fs.existsSync(README_PATH)) {
console.error("README.md not found");
process.exit(1);
}
if (!fs.existsSync(SKILLS_DIR)) {
console.error("/skills directory not found");
process.exit(1);
}
const count = countSkills(SKILLS_DIR);
const formatted = formatNumber(count);
let readme = fs.readFileSync(README_PATH, "utf8");
readme = replaceOrWarn(
readme,
/skills=\d+/,
`skills=${count}`,
"registry-sync comment"
);
readme = replaceOrWarn(
readme,
/(# 🌌 Antigravity Awesome Skills:\s*)[\d,]+\+/,
`$1${formatted}+`,
"main title"
);
readme = replaceOrWarn(
readme,
/(Installable GitHub library of )[\d,]+\+/,
`$1${formatted}+`,
"subtitle"
);
readme = readme.replace(
/Browse [\d,]+\+ Skills/g,
`Browse ${formatted}+ Skills`
);
readme = readme.replace(
/browse all [\d,]+\+ skills/gi,
`browse all ${formatted}+ skills`
);
readme = readme.replace(
/([\s:])[\d,]+\+ skills across/g,
`$1${formatted}+ skills across`
);
readme = readme.replace(
/\(#browse-\d+-skills\)/g,
`(#browse-${count}-skills)`
);
readme = readme.replace(
/## Browse [\d,]+\+ Skills/g,
`## Browse ${formatted}+ Skills`
);
fs.writeFileSync(README_PATH, readme);
console.log(`✅ README synced successfully`);
console.log(`📦 Skills detected: ${count}`);
console.log(`📝 README updated: README.md`);