@@ -3,7 +3,7 @@ import { writeFileSync, readFileSync } from 'fs';
33import https from 'https' ;
44
55const repo = 'zumerlab/snapdom' ;
6- const readmePath = 'README.md' ;
6+ const readmePaths = [ 'README.md' , 'README_CN.md' ] ;
77
88function fetchContributors ( ) {
99 const options = {
@@ -13,25 +13,27 @@ function fetchContributors() {
1313 } ;
1414
1515 return new Promise ( ( resolve , reject ) => {
16- https . get ( options , ( res ) => {
17- let body = '' ;
18- res . on ( 'data' , chunk => ( body += chunk ) ) ;
19- res . on ( 'end' , ( ) => {
20- if ( res . statusCode === 200 ) {
21- resolve ( JSON . parse ( body ) ) ;
22- } else {
23- reject ( new Error ( `GitHub API error: ${ res . statusCode } ` ) ) ;
24- }
25- } ) ;
26- } ) . on ( 'error' , reject ) ;
16+ https
17+ . get ( options , ( res ) => {
18+ let body = '' ;
19+ res . on ( 'data' , ( chunk ) => ( body += chunk ) ) ;
20+ res . on ( 'end' , ( ) => {
21+ if ( res . statusCode === 200 ) {
22+ resolve ( JSON . parse ( body ) ) ;
23+ } else {
24+ reject ( new Error ( `GitHub API error: ${ res . statusCode } ` ) ) ;
25+ }
26+ } ) ;
27+ } )
28+ . on ( 'error' , reject ) ;
2729 } ) ;
2830}
2931
3032function buildHTML ( contributors ) {
3133 return (
3234 '\n<p>\n' +
3335 contributors
34- . map ( c => {
36+ . map ( ( c ) => {
3537 const avatar = `<a href="${ c . html_url } " title="${ c . login } "><img src="${ c . avatar_url } &s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="${ c . login } "/></a>` ;
3638 return avatar ;
3739 } )
@@ -40,22 +42,29 @@ function buildHTML(contributors) {
4042 ) ;
4143}
4244
43- function updateReadme ( contributorHTML ) {
44- const content = readFileSync ( readmePath , 'utf8' ) ;
45- const updated = content . replace (
46- / < ! - - C O N T R I B U T O R S : S T A R T - - > ( [ \s \S ] * ?) < ! - - C O N T R I B U T O R S : E N D - - > / ,
47- `<!-- CONTRIBUTORS:START -->${ contributorHTML } <!-- CONTRIBUTORS:END -->`
48- ) ;
49- writeFileSync ( readmePath , updated ) ;
45+ function updateReadmes ( contributorHTML ) {
46+ for ( const path of readmePaths ) {
47+ try {
48+ const content = readFileSync ( path , 'utf8' ) ;
49+ const updated = content . replace (
50+ / < ! - - C O N T R I B U T O R S : S T A R T - - > ( [ \s \S ] * ?) < ! - - C O N T R I B U T O R S : E N D - - > / ,
51+ `<!-- CONTRIBUTORS:START -->${ contributorHTML } <!-- CONTRIBUTORS:END -->`
52+ ) ;
53+ writeFileSync ( path , updated ) ;
54+ } catch ( ) {
55+ }
56+ }
5057}
5158
5259fetchContributors ( )
53- . then ( contributors => {
54- const filtered = contributors . filter ( c => c . type !== 'Bot' && c . login !== 'github-actions[bot]' ) ;
60+ . then ( ( contributors ) => {
61+ const filtered = contributors . filter (
62+ ( c ) => c . type !== 'Bot' && c . login !== 'github-actions[bot]'
63+ ) ;
5564 const html = buildHTML ( filtered ) ;
56- updateReadme ( html ) ;
65+ updateReadmes ( html ) ;
5766 } )
58- . catch ( err => {
67+ . catch ( ( err ) => {
5968 console . error ( 'Error fetching contributors:' , err ) ;
6069 process . exit ( 1 ) ;
6170 } ) ;
0 commit comments