feat(ci): create doc PRs, maybe?

This commit is contained in:
rektdeckard
2024-12-28 21:50:33 -07:00
committed by Tobias Fried
parent 5a390a9231
commit a4421c82b2
6 changed files with 145 additions and 3 deletions

41
scripts/sync-docs.ts Normal file
View File

@@ -0,0 +1,41 @@
import fs from "node:fs";
import path from "node:path";
const SYNC_SECTIONS = ["LINKS"];
(function main() {
const targetRepo = process.argv[process.argv.length - 1];
if (!targetRepo) throw new Error("Target repository not provided");
const targetReadmePath = path.resolve(__dirname, `../../${targetRepo}/README.md`);
if (!fs.existsSync(targetReadmePath)) throw new Error(`README.md not found in ${targetRepo}`);
const readmePath = path.resolve(__dirname, "../README.md");
const readmeContent = fs.readFileSync(readmePath, "utf8");
for (const section of SYNC_SECTIONS) {
const sectionContent = extractSection(readmeContent, section);
if (!sectionContent) throw new Error(`Section ${section} not found in README.md`);
const targetReadmeContent = fs.readFileSync(targetReadmePath, "utf8");
const updatedDocsContent = updateSection(targetReadmeContent, section, sectionContent);
fs.writeFileSync(targetReadmePath, updatedDocsContent);
}
})();
function extractSection(content: string, section: string) {
const pattern = new RegExp(
`<!-- BEGIN_${section} -->\n([\\s\\S]*)\n<!-- END_${section} -->`,
"g",
);
const match = pattern.exec(content);
return match?.[1];
}
function updateSection(content: string, section: string, newContent: string) {
const pattern = new RegExp(
`<!-- BEGIN_${section} -->\n([\\s\\S]*)\n<!-- END_${section} -->`,
"g",
);
return content.replace(pattern, `<!-- BEGIN_${section} -->\n${newContent}\n<!-- END_${section} -->`);
}