@@ -12,11 +12,27 @@ if (!fs.existsSync(parsedBadgesPath)) {
1212const parsedBadges = JSON . parse ( fs . readFileSync ( parsedBadgesPath , 'utf8' ) ) ;
1313let readmeContent = fs . readFileSync ( readmePath , 'utf8' ) ;
1414
15+ // Extract the plugins list section
16+ const pluginsListRegex = / < ! - - S T A R T P L U G I N S L I S T - - > ( [ \s \S ] * ?) < ! - - E N D P L U G I N S L I S T - - > / ;
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 ] ;
1525let changesMade = false ;
1626
27+ // Process each plugin from parsed badges
1728parsedBadges . 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
3753if ( 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