Skip to content

Commit c1acf8b

Browse files
authored
Update update-readme.js
1 parent f6e2996 commit c1acf8b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

update-readme.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (!sectionMatch) {
1515
const pluginsListContent = sectionMatch[1].trim();
1616

1717
// Regex to match individual plugin entries
18-
const pluginRegex = /- ### (.+?).*?!GitHub Downloads all releases(https:\/\/img\.shields\.io\/github\/downloads\/.+?\/total)(.+?)/g;
18+
const pluginRegex = /- ### (.+?)\s*!GitHub Downloads all releases(https:\/\/img\.shields\.io\/github\/downloads\/.+?\/total)(.+?)/g;
1919
const readmePlugins = new Map();
2020
let match;
2121

@@ -48,24 +48,25 @@ parsedBadges.forEach(({ name, latestReleaseUrl }) => {
4848

4949
if (pluginEntry) {
5050
console.log(`\nChecking plugin: ${name}`);
51-
console.log(`Current download URL: ${pluginEntry.currentDownloadUrl}`);
52-
console.log(`Latest release URL: ${latestReleaseUrl}`);
51+
console.log(`Current download URL in README: ${pluginEntry.currentDownloadUrl}`);
52+
console.log(`Latest release URL from badges.json: ${latestReleaseUrl}`);
5353

54-
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${name}/total`;
55-
56-
// Check if URLs need updating
54+
// Check if the download URL needs updating
5755
if (pluginEntry.currentDownloadUrl !== latestReleaseUrl) {
5856
console.log(`Updating download URL for ${name}`);
57+
58+
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${name}/total`;
5959
const newBadge = `[![GitHub Downloads (all releases)](${expectedBadgeUrl})](${latestReleaseUrl})`;
6060

61-
// Update the plugin entry in the README
61+
// Construct the old and new plugin entries
6262
const oldEntry = `- ### [${pluginEntry.pluginName}] [![GitHub Downloads (all releases)](${pluginEntry.currentBadgeUrl})](${pluginEntry.currentDownloadUrl})`;
6363
const newEntry = `- ### [${pluginEntry.pluginName}] ${newBadge}`;
6464

65+
// Replace the old entry with the new one in the README
6566
readmeContent = readmeContent.replace(oldEntry, newEntry);
6667
changesMade = true;
6768
} else {
68-
console.log(`No update needed for ${name}, URLs match.`);
69+
console.log(`No update needed for ${name}`);
6970
}
7071
} else {
7172
console.log(`No matching plugin found in README for ${name}`);
@@ -74,7 +75,7 @@ parsedBadges.forEach(({ name, latestReleaseUrl }) => {
7475

7576
// Write updated README if changes were made
7677
if (changesMade) {
77-
console.log('\nChanges detected, updating README...');
78+
console.log('Changes detected, updating README...');
7879
fs.writeFileSync('README.md', readmeContent, 'utf8');
7980
console.log('README updated successfully.');
8081
} else {

0 commit comments

Comments
 (0)