@@ -15,58 +15,54 @@ if (!sectionMatch) {
1515const pluginsListContent = sectionMatch [ 1 ] . trim ( ) ;
1616
1717// Regex to match individual plugin entries
18- const pluginRegex = / - # # # ( .+ ?) \s * ! G i t H u b D o w n l o a d s a l l r e l e a s e s ( h t t p s : \/ \/ i m g \. s h i e l d s \. i o \/ g i t h u b \/ d o w n l o a d s \/ . + ? \/ t o t a l ) ( . + ? ) / g;
19- const readmePlugins = new Map ( ) ;
18+ const pluginRegex = / - # # # ( .+ ?) / g;
19+ const pluginNames = [ ] ;
2020let match ;
2121
22- // Extract plugin names and URLs from README
2322while ( ( match = pluginRegex . exec ( pluginsListContent ) ) !== null ) {
24- const pluginName = match [ 1 ] . trim ( ) ;
25- const currentBadgeUrl = match [ 2 ] . trim ( ) ;
26- const currentDownloadUrl = match [ 3 ] . trim ( ) ;
27- readmePlugins . set ( pluginName . toLowerCase ( ) , { pluginName, currentBadgeUrl, currentDownloadUrl } ) ;
23+ pluginNames . push ( match [ 1 ] . trim ( ) ) ;
2824}
2925
3026// Log parsed plugin names from README
31- console . log ( 'Parsed plugin names from README:' , Array . from ( readmePlugins . keys ( ) ) ) ;
27+ console . log ( 'Parsed plugin names from README:' , pluginNames ) ;
3228
33- if ( readmePlugins . size === 0 ) {
29+ if ( pluginNames . length === 0 ) {
3430 console . error ( 'No plugins were found. Please check the README format.' ) ;
3531 process . exit ( 1 ) ;
3632}
3733
3834// Load parsed badges
3935const parsedBadges = JSON . parse ( fs . readFileSync ( process . argv [ 2 ] , 'utf8' ) ) . plugins ;
4036
37+ // Map plugin names from the README for easier matching
38+ const readmePlugins = new Map ( pluginNames . map ( name => [ name . toLowerCase ( ) , name ] ) ) ;
39+
4140// Flag to track changes
4241let changesMade = false ;
4342
4443// Iterate over parsed badges to find matching plugins in the README
4544parsedBadges . forEach ( ( { name, latestReleaseUrl } ) => {
4645 const normalizedPluginName = name . toLowerCase ( ) ;
47- const pluginEntry = readmePlugins . get ( normalizedPluginName ) ;
48-
49- if ( pluginEntry ) {
50- console . log ( `\nChecking plugin: ${ name } ` ) ;
51- console . log ( `Current download URL in README: ${ pluginEntry . currentDownloadUrl } ` ) ;
52- console . log ( `Latest release URL from badges.json: ${ latestReleaseUrl } ` ) ;
46+ console . log ( `Checking plugin: ${ name } ` ) ;
47+ console . log ( `Latest release URL: ${ latestReleaseUrl } ` ) ;
5348
54- // Check if the download URL needs updating
55- if ( pluginEntry . currentDownloadUrl !== latestReleaseUrl ) {
56- console . log ( `Updating download URL for ${ name } ` ) ;
49+ if ( readmePlugins . has ( normalizedPluginName ) ) {
50+ console . log ( `Matching plugin found in README for ${ name } ` ) ;
5751
58- const expectedBadgeUrl = `https://img.shields.io/github/downloads/ ${ name } /total` ;
59- const newBadge = `[]( ${ latestReleaseUrl } ) ` ;
52+ // Construct the expected badge URL
53+ const expectedBadgeUrl = `https://img.shields.io/github/downloads/ ${ name } /total ` ;
6054
61- // Construct the old and new plugin entries
62- const oldEntry = `- ### [${ pluginEntry . pluginName } ] [](${ pluginEntry . currentDownloadUrl } )` ;
63- const newEntry = `- ### [${ pluginEntry . pluginName } ] ${ newBadge } ` ;
55+ // Regex to find and replace badge and download URL
56+ const badgeRegex = new RegExp (
57+ `\!\GitHub Downloads \all releases\\\https://img\\.shields\\.io/github/downloads/.+?/total\\\.*?\` ,
58+ 'g'
59+ ) ;
60+ const newBadge = `[](${ latestReleaseUrl } )` ;
61+ const updatedContent = readmeContent . replace ( badgeRegex , newBadge ) ;
6462
65- // Replace the old entry with the new one in the README
66- readmeContent = readmeContent . replace ( oldEntry , newEntry ) ;
63+ if ( updatedContent !== readmeContent ) {
64+ readmeContent = updatedContent ;
6765 changesMade = true ;
68- } else {
69- console . log ( `No update needed for ${ name } ` ) ;
7066 }
7167 } else {
7268 console . log ( `No matching plugin found in README for ${ name } ` ) ;
0 commit comments