Skip to content

Commit e808593

Browse files
authored
Update update-readme.js
1 parent ec40adc commit e808593

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

update-readme.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ if (!sectionMatch) {
1515
const pluginsListContent = sectionMatch[1].trim();
1616
console.log('Extracted plugins list content:\n', pluginsListContent);
1717

18-
// Updated regex to match plugin entries
19-
const pluginRegex = /- ### ([^]+)/g;
18+
// Regex to match individual plugin entries
19+
const pluginRegex = /- ### ([^]+)/g;
2020
const pluginNames = [];
2121
let match;
2222

@@ -33,7 +33,7 @@ if (pluginNames.length === 0) {
3333
process.exit(1);
3434
}
3535

36-
// Load parsed badges
36+
// Load parsed badges from badges.json
3737
const parsedBadges = JSON.parse(fs.readFileSync(process.argv[2], 'utf8')).plugins;
3838

3939
// Map plugin names from the README for easier matching
@@ -51,25 +51,19 @@ parsedBadges.forEach(({ name, latestReleaseUrl }) => {
5151
if (readmePlugins.has(normalizedPluginName)) {
5252
console.log(`Matching plugin found in README for ${name}`);
5353

54-
// Construct the expected badge URL
55-
const expectedBadgeUrl = `https://img.shields.io/github/downloads/${name}/total`;
56-
57-
// Regex to find the current entry in README
54+
// Regex to find the current download badge entry for this plugin
5855
const badgeRegex = new RegExp(
59-
`- ### \${readmePlugins.get(normalizedPluginName)}\ \!\GitHub Downloads \all releases\\\https://img\\.shields\\.io/github/downloads/.+?/total\\\.*?\`,
56+
`\!\GitHub Downloads \all releases\\\https://img\\.shields\\.io/github/downloads/${normalizedPluginName}/total\\\(.*?)\`,
6057
'g'
6158
);
6259

63-
// Check if the current download URL in README differs from the latest release URL
64-
const currentEntry = readmeContent.match(badgeRegex);
65-
if (currentEntry && !currentEntry[0].includes(latestReleaseUrl)) {
60+
const match = badgeRegex.exec(readmeContent);
61+
if (match && match[1] !== latestReleaseUrl) {
6662
console.log(`Updating download URL for ${name}`);
63+
const updatedBadge = `[![GitHub Downloads (all releases)](https://img.shields.io/github/downloads/${normalizedPluginName}/total)](${latestReleaseUrl})`;
6764

68-
// Construct the new entry
69-
const newEntry = `- ### [${readmePlugins.get(normalizedPluginName)}] [![GitHub Downloads (all releases)](${expectedBadgeUrl})](${latestReleaseUrl})`;
70-
71-
// Replace the old entry with the new one in the README
72-
readmeContent = readmeContent.replace(badgeRegex, newEntry);
65+
// Replace the old badge with the updated one
66+
readmeContent = readmeContent.replace(badgeRegex, updatedBadge);
7367
changesMade = true;
7468
} else {
7569
console.log(`No update needed for ${name}`);

0 commit comments

Comments
 (0)