| 890 | |
| 891 | // Utility: write file only if content changed |
| 892 | function writeFileIfChanged(filePath, content) { |
| 893 | const exists = fs.existsSync(filePath); |
| 894 | if (exists) { |
| 895 | const original = fs.readFileSync(filePath, "utf8"); |
| 896 | if (original === content) { |
| 897 | console.log( |
| 898 | `${path.basename(filePath)} is already up to date. No changes needed.` |
| 899 | ); |
| 900 | return; |
| 901 | } |
| 902 | } |
| 903 | fs.writeFileSync(filePath, content); |
| 904 | console.log( |
| 905 | `${path.basename(filePath)} ${exists ? "updated" : "created"} successfully!` |
| 906 | ); |
| 907 | } |
| 908 | |
| 909 | // Build per-category README content using existing generators, upgrading headings to H1 |
| 910 | function buildCategoryReadme( |