@@ -9,6 +9,10 @@ const __dirname = dirname(__filename);
99const shouldFix = process . argv . includes ( '--fix' ) ;
1010
1111// Extract badge info from README file
12+ /**
13+ *
14+ * @param filePath
15+ */
1216function extractBadgeInfo ( filePath ) {
1317 const content = readFileSync ( filePath , 'utf8' ) ;
1418 const badgeRegex =
@@ -38,6 +42,11 @@ function extractBadgeInfo(filePath) {
3842}
3943
4044// Fix badge colors in README file
45+ /**
46+ *
47+ * @param filePath
48+ * @param colorChanges
49+ */
4150function fixBadgeColors ( filePath , colorChanges ) {
4251 let content = readFileSync ( filePath , 'utf8' ) ;
4352 let changeCount = 0 ;
@@ -69,6 +78,9 @@ function fixBadgeColors(filePath, colorChanges) {
6978 return 0 ;
7079}
7180
81+ /**
82+ *
83+ */
7284async function fetchSimpleIcons ( ) {
7385 const response = await fetch (
7486 'https://raw.githubusercontent.com/simple-icons/simple-icons/refs/heads/develop/data/simple-icons.json'
@@ -86,16 +98,17 @@ async function fetchSimpleIcons() {
8698 return iconMap ;
8799}
88100
89- async function main ( ) {
90- console . log ( 'Fetching Simple Icons data...\n' ) ;
91- const simpleIcons = await fetchSimpleIcons ( ) ;
92-
93- // Get badge info from README files (one level up from scripts directory)
94- const readmePath = join ( __dirname , '..' , 'README.md' ) ;
95- const readmeEnPath = join ( __dirname , '..' , 'README.en.md' ) ;
96- const currentBadges = extractBadgeInfo ( readmePath ) ;
97-
98- console . log ( 'Verifying badge colors:\n' ) ;
101+ /**
102+ *
103+ * @param filePath
104+ * @param simpleIcons
105+ */
106+ function checkReadme ( filePath , simpleIcons ) {
107+ const fileName = filePath . split ( / [ \\ / ] / ) . pop ( ) ;
108+ const currentBadges = extractBadgeInfo ( filePath ) ;
109+
110+ console . log ( `\n${ '=' . repeat ( 80 ) } ` ) ;
111+ console . log ( `📄 ${ fileName } ` ) ;
99112 console . log ( '=' . repeat ( 80 ) ) ;
100113 console . log (
101114 'Logo Name' . padEnd ( 25 ) + 'Current Color' . padEnd ( 20 ) + 'Official Color' . padEnd ( 20 ) + 'Status'
@@ -141,14 +154,13 @@ async function main() {
141154 }
142155
143156 console . log ( '=' . repeat ( 80 ) ) ;
144- console . log ( `\nSummary:` ) ;
157+ console . log ( `\nSummary for ${ fileName } :` ) ;
145158 console . log ( `Total badges checked: ${ totalChecked } ` ) ;
146159 console . log ( `✅ Correct: ${ correctCount } ` ) ;
147160 console . log ( `❌ Incorrect: ${ incorrectCount } ` ) ;
148161
149162 if ( Object . keys ( issues ) . length > 0 ) {
150- console . log ( '\n\n🔧 Badges that need updating:\n' ) ;
151- console . log ( '=' . repeat ( 80 ) ) ;
163+ console . log ( '\n🔧 Badges that need updating:\n' ) ;
152164 Object . entries ( issues ) . forEach ( ( [ logo , issue ] ) => {
153165 console . log ( `${ logo } :` ) ;
154166 console . log ( ` Current: ${ issue . current } ` ) ;
@@ -157,21 +169,43 @@ async function main() {
157169 } ) ;
158170
159171 if ( shouldFix ) {
160- console . log ( '\n🔧 Applying fixes...\n' ) ;
172+ console . log ( '🔧 Applying fixes...\n' ) ;
173+ const fixedCount = fixBadgeColors ( filePath , issues ) ;
174+ console . log ( `✅ Fixed ${ fixedCount } badge(s) in ${ fileName } ` ) ;
175+ }
176+ } else {
177+ console . log ( '\n🎉 All badge colors are correct!' ) ;
178+ }
161179
162- const fixedCount1 = fixBadgeColors ( readmePath , issues ) ;
163- console . log ( `\n✅ Fixed ${ fixedCount1 } badge(s) in README.md` ) ;
180+ return issues ;
181+ }
164182
165- const fixedCount2 = fixBadgeColors ( readmeEnPath , issues ) ;
166- console . log ( `✅ Fixed ${ fixedCount2 } badge(s) in README.en.md` ) ;
183+ /**
184+ *
185+ */
186+ async function main ( ) {
187+ console . log ( 'Fetching Simple Icons data...\n' ) ;
188+ const simpleIcons = await fetchSimpleIcons ( ) ;
167189
168- console . log ( '\n🎉 All badge colors have been fixed!' ) ;
169- } else {
170- console . log ( '\n💡 Tip: Run with --fix flag to automatically fix all mismatches:' ) ;
171- console . log ( ' node scripts/fix-badge-colors.js --fix\n' ) ;
172- }
190+ const readmes = [
191+ join ( __dirname , '..' , 'README.md' ) ,
192+ join ( __dirname , '..' , 'README.zh-Hans.md' ) ,
193+ join ( __dirname , '..' , 'README.zh-Hant.md' )
194+ ] ;
195+
196+ let anyIssues = false ;
197+ for ( const readmePath of readmes ) {
198+ const issues = checkReadme ( readmePath , simpleIcons ) ;
199+ if ( Object . keys ( issues ) . length > 0 ) anyIssues = true ;
200+ }
201+
202+ if ( anyIssues && ! shouldFix ) {
203+ console . log ( '\n💡 Tip: Run with --fix flag to automatically fix all mismatches:' ) ;
204+ console . log ( ' node scripts/fix-badge-colors.js --fix\n' ) ;
205+ } else if ( ! anyIssues ) {
206+ console . log ( '\n🎉 All badge colors across all READMEs are correct!' ) ;
173207 } else {
174- console . log ( '\n🎉 All badge colors are correct !' ) ;
208+ console . log ( '\n🎉 All badge colors have been fixed !' ) ;
175209 }
176210}
177211
0 commit comments