@@ -10,24 +10,43 @@ if (!username) {
1010const readmePath = path . join ( process . cwd ( ) , 'README.md' ) ;
1111let readme = fs . readFileSync ( readmePath , 'utf8' ) ;
1212
13- const contribSectionRegex = / ( # # C o n t r i b u t o r s \s * \n ) ( (?: .| \n ) * ?) ( \n # # | \n # | \n $ ) / ;
13+ // Where to add the Contributors section (after "Thanks for being part of Codextream")
14+ const thankYouMarker = "## 🙌 Thanks for being part of Codextream!" ;
15+
16+ // Contributor markdown line
1417const contributorLine = `- [@${ username } ](https://github.com/${ username } )` ;
1518
19+ // Check if already present
1620if ( readme . includes ( contributorLine ) ) {
1721 console . log ( 'Contributor already present. Skipping.' ) ;
1822 process . exit ( 0 ) ;
1923}
2024
21- if ( contribSectionRegex . test ( readme ) ) {
22- // Add to existing Contributors section
25+ const contributorsHeader = "## Contributors" ;
26+ const insertSection = `\n${ contributorsHeader } \n${ contributorLine } \n` ;
27+
28+ if ( readme . includes ( contributorsHeader ) ) {
29+ // Add to existing Contributors section (append if not present)
30+ const contribSectionRegex = / ( # # C o n t r i b u t o r s \s * \n ) ( (?: .| \n ) * ?) ( \n # # | \n # | \n $ ) / ;
2331 readme = readme . replace (
2432 contribSectionRegex ,
25- ( _ , sectionHeader , sectionBody , sectionEnd ) =>
26- `${ sectionHeader } ${ sectionBody } ${ contributorLine } \n${ sectionEnd } `
33+ ( match , sectionHeader , sectionBody , sectionEnd ) => {
34+ if ( sectionBody . includes ( contributorLine ) ) {
35+ return match ; // Already present
36+ }
37+ return `${ sectionHeader } ${ sectionBody } ${ contributorLine } \n${ sectionEnd } ` ;
38+ }
2739 ) ;
40+ } else if ( readme . includes ( thankYouMarker ) ) {
41+ // Add Contributors section after Thank You marker
42+ const thankYouIndex = readme . indexOf ( thankYouMarker ) ;
43+ const afterThankYouIndex = readme . indexOf ( '\n' , thankYouIndex ) ;
44+ const before = readme . slice ( 0 , afterThankYouIndex + 1 ) ;
45+ const after = readme . slice ( afterThankYouIndex + 1 ) ;
46+ readme = before + insertSection + after ;
2847} else {
29- // Add new Contributors section at the end
30- readme += `\n## Contributors\n ${ contributorLine } \n` ;
48+ // Fallback: append at end
49+ readme += insertSection ;
3150}
3251
3352fs . writeFileSync ( readmePath , readme , 'utf8' ) ;
0 commit comments