@@ -15,8 +15,8 @@ if (!sectionMatch) {
1515const pluginsListContent = sectionMatch [ 1 ] . trim ( ) ;
1616console . 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;
2020const pluginNames = [ ] ;
2121let 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
3737const 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 = `[](${ latestReleaseUrl } )` ;
6764
68- // Construct the new entry
69- const newEntry = `- ### [${ readmePlugins . get ( normalizedPluginName ) } ] [](${ 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