Skip to content

Commit 62c1f6c

Browse files
authored
Update update-readme.js
1 parent a79bd2c commit 62c1f6c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

update-readme.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,27 @@ if (!fs.existsSync(parsedBadgesPath)) {
1212
const parsedBadges = JSON.parse(fs.readFileSync(parsedBadgesPath, 'utf8'));
1313
let readmeContent = fs.readFileSync(readmePath, 'utf8');
1414

15+
// Extract the plugins list section
16+
const pluginsListRegex = /<!-- START PLUGINS LIST -->([\s\S]*?)<!-- END PLUGINS LIST -->/;
17+
const match = readmeContent.match(pluginsListRegex);
18+
19+
if (!match) {
20+
console.error('Error: Plugins list section not found in README.');
21+
process.exit(1);
22+
}
23+
24+
let pluginsSection = match[1];
1525
let changesMade = false;
1626

27+
// Process each plugin from parsed badges
1728
parsedBadges.forEach((plugin) => {
29+
if (!plugin.repo || !plugin.latestReleaseUrl) {
30+
console.log(`Skipping plugin: ${plugin.name} due to missing repo or URL.`);
31+
return;
32+
}
33+
1834
const badgeRegex = new RegExp(
19-
`\\\!\GitHub Downloads \all releases\\\https:\\/\\/img\\.shields\\.io\\/github\\/downloads\\/${plugin.repo}\\/total\\\https:\\/\\/github\\.com\\/${plugin.repo}\\/releases\\/download\\/.*\`,
35+
`\\\!\GitHub Downloads \all releases\\\https:\\/\\/img\\.shields\\.io\\/github\\/downloads\\/${plugin.repo}\\/total\\\https:\\/\\/github\\.com\\/${plugin.repo}\\/releases\\/download\\/[^)]+\`,
2036
'g'
2137
);
2238

@@ -25,20 +41,25 @@ parsedBadges.forEach((plugin) => {
2541
console.log(`Checking plugin: ${plugin.name}`);
2642
console.log(`Expected badge line: ${newBadgeLine}`);
2743

28-
if (badgeRegex.test(readmeContent)) {
44+
if (badgeRegex.test(pluginsSection)) {
2945
console.log(`Badge found for ${plugin.name}. Updating...`);
30-
readmeContent = readmeContent.replace(badgeRegex, newBadgeLine);
46+
pluginsSection = pluginsSection.replace(badgeRegex, newBadgeLine);
3147
changesMade = true;
3248
} else {
3349
console.log(`No matching badge found for ${plugin.name}.`);
3450
}
3551
});
3652

3753
if (changesMade) {
54+
// Replace the old plugins list section with the updated one
55+
readmeContent = readmeContent.replace(
56+
pluginsListRegex,
57+
`<!-- START PLUGINS LIST -->\n${pluginsSection}\n<!-- END PLUGINS LIST -->`
58+
);
3859
fs.writeFileSync(readmePath, readmeContent);
3960
console.log('README updated with latest download URLs.');
40-
process.exit(0); // Indicate changes were made
61+
process.exit(0);
4162
} else {
4263
console.log('No changes made to README.');
43-
process.exit(1); // Indicate no changes were made
64+
process.exit(1);
4465
}

0 commit comments

Comments
 (0)