11import yaml
22import re
33import os
4+ import difflib
45
56# -----------------------
67# Load YAML data
@@ -21,21 +22,17 @@ def generate_entry_md(entry, is_plugin=True, index=0):
2122 md += f" [](https://github.com/{ entry ['repo' ]} /releases) "
2223 md += f"[](https://github.com/{ entry ['repo' ]} /releases/download/{ entry .get ('latest_release_tag' , 'latest' )} /{ sanitized_name } .jar)<br>\n "
2324
24- # MC version + core plugin badge
2525 if is_plugin and 'mc_versions' in entry :
2626 mc_versions = entry ['mc_versions' ].replace ('-' , '--' ).replace ('.' , '%20' )
2727 md += f" <br>\n "
2828 if is_plugin and entry .get ('is_core' , False ):
2929 md += " <br>\n "
3030
31- # Creator
3231 md += f" **Creator**: <img src=\" { entry ['creator' ]['avatar' ]} \" width=\" 20\" height=\" 20\" > [{ entry ['creator' ]['name' ]} ]({ entry ['creator' ]['url' ]} )<br>\n "
3332
34- # Description (remove image markdown if any)
3533 cleaned_description = re .sub (r'!\[.*?\]\(.*?\)' , '' , entry ['description' ])
3634 md += f" { cleaned_description .strip ()} \n \n "
3735
38- # Screenshots and YouTube thumbnails
3936 if entry .get ('screenshots' ):
4037 md += " <details>\n <summary>Show Screenshots</summary>\n <p align=\" center\" >\n "
4138 for ss in entry ['screenshots' ]:
@@ -75,7 +72,7 @@ def generate_entry_md(entry, is_plugin=True, index=0):
7572
7673with open ('PLUGINS.md' , 'w' ) as f :
7774 f .write (plugins_content )
78- print ("Updated PLUGINS.md" )
75+ print ("✅ Updated PLUGINS.md" )
7976
8077# -----------------------
8178# Update THEMES.md
@@ -94,40 +91,49 @@ def generate_entry_md(entry, is_plugin=True, index=0):
9491
9592with open ('THEMES.md' , 'w' ) as f :
9693 f .write (themes_content )
97- print ("Updated THEMES.md" )
94+ print ("✅ Updated THEMES.md" )
9895
9996# -----------------------
100- # Update badge counts in README.md (resilient version )
97+ # Update badge counts in README.md (flexible )
10198# -----------------------
102- with open ( 'README.md' , 'r' ) as f :
103- readme_content = f . read ( )
99+ print ( "📁 Working directory:" , os . getcwd ())
100+ print ( "📄 README.md path:" , os . path . abspath ( 'README.md' ) )
104101
105- # Debug: before replacement
106- print ("Searching for plugin badge..." )
107- plugin_match = re .search (r'\[!\[Plugins\]\(.*?shields\.io/badge/Plugins-\d+-green.*?\)\]\([^)]+\)' , readme_content )
108- print ("Plugin badge found:" , bool (plugin_match ))
102+ with open ('README.md' , 'r' ) as f :
103+ readme_original = f .read ()
109104
110- print ("Searching for theme badge..." )
111- theme_match = re .search (r'\[!\[Themes\]\(.*?shields\.io/badge/Themes-\d+-green.*?\)\]\([^)]+\)' , readme_content )
112- print ("Theme badge found:" , bool (theme_match ))
105+ # Check for matches
106+ plugin_match = re .search (r'\[!\[Plugins\]\(.*?shields\.io/badge/Plugins-\d+-green.*?\)\]\([^)]+\)' , readme_original )
107+ theme_match = re .search (r'\[!\[Themes\]\(.*?shields\.io/badge/Themes-\d+-green.*?\)\]\([^)]+\)' , readme_original )
108+ print ("🔍 Plugin badge found:" , bool (plugin_match ))
109+ print ("🔍 Theme badge found:" , bool (theme_match ))
113110
114- # Replace badges
115- readme_content = re .sub (
111+ # Apply replacements
112+ readme_updated = re .sub (
116113 r'\[!\[Plugins\]\(.*?shields\.io/badge/Plugins-\d+-green.*?\)\]\([^)]+\)' ,
117114 f'[](./PLUGINS.md)' ,
118- readme_content ,
115+ readme_original ,
119116 count = 1
120117)
121118
122- readme_content = re .sub (
119+ readme_updated = re .sub (
123120 r'\[!\[Themes\]\(.*?shields\.io/badge/Themes-\d+-green.*?\)\]\([^)]+\)' ,
124121 f'[](./THEMES.md)' ,
125- readme_content ,
122+ readme_updated ,
126123 count = 1
127124)
128125
129- with open ('README.md' , 'w' ) as f :
130- f .write (readme_content )
131- print ("README.md updated." )
132-
133- print ("README.md last modified:" , os .path .getmtime ('README.md' ))
126+ # Diff check
127+ if readme_original == readme_updated :
128+ print ("✅ README.md was already up to date." )
129+ else :
130+ print ("✏️ README.md was changed. Writing changes..." )
131+ with open ('README.md' , 'w' ) as f :
132+ f .write (readme_updated )
133+ print ("✅ README.md updated." )
134+ print ("--- README.md DIFF ---" )
135+ for line in difflib .unified_diff (readme_original .splitlines (), readme_updated .splitlines (), fromfile = 'before' , tofile = 'after' , lineterm = '' ):
136+ print (line )
137+ print ("--- END DIFF ---" )
138+
139+ print ("🕒 README.md last modified:" , os .path .getmtime ('README.md' ))
0 commit comments