1313// Requirements
1414//-----------------------------------------------------------------------------
1515
16- const path = require ( "path" ) ;
1716const fs = require ( "fs" ) ;
1817const { stripIndents } = require ( "common-tags" ) ;
1918const ejs = require ( "ejs" ) ;
19+ const got = require ( "got" ) ;
2020
2121//-----------------------------------------------------------------------------
2222// Data
2323//-----------------------------------------------------------------------------
2424
25- const README_FILE_PATH = path . resolve ( __dirname , "../README.md" ) ;
26- const WEBSITE_DATA_PATH = path . resolve ( __dirname , "../../website/_data" ) ;
25+ const SPONSORS_URL = "https://raw.githubusercontent.com/eslint/eslint.org/main/src/_data/sponsors.json" ;
26+ const TEAM_URL = "https://raw.githubusercontent.com/eslint/eslint.org/main/src/_data/team.json" ;
27+ const README_FILE_PATH = "./README.md" ;
2728
28- const team = JSON . parse ( fs . readFileSync ( path . join ( WEBSITE_DATA_PATH , "team.json" ) ) ) ;
29- const allSponsors = JSON . parse ( fs . readFileSync ( path . join ( WEBSITE_DATA_PATH , "sponsors.json" ) ) ) ;
3029const readme = fs . readFileSync ( README_FILE_PATH , "utf8" ) ;
3130
3231const heights = {
@@ -35,13 +34,31 @@ const heights = {
3534 bronze : 32
3635} ;
3736
38- // remove backers from sponsors list - not shown on readme
39- delete allSponsors . backers ;
40-
4137//-----------------------------------------------------------------------------
4238// Helpers
4339//-----------------------------------------------------------------------------
4440
41+ /**
42+ * Fetches the latest sponsors data from the website.
43+ * @returns {Object } The sponsors data object.
44+ */
45+ async function fetchSponsorsData ( ) {
46+ const data = await got ( SPONSORS_URL ) . json ( ) ;
47+
48+ // remove backers from sponsors list - not shown on readme
49+ delete data . backers ;
50+
51+ return data ;
52+ }
53+
54+ /**
55+ * Fetches the latest team data from the website.
56+ * @returns {Object } The sponsors data object.
57+ */
58+ async function fetchTeamData ( ) {
59+ return got ( TEAM_URL ) . json ( ) ;
60+ }
61+
4562/**
4663 * Formats an array of team members for inclusion in the readme.
4764 * @param {Array } members The array of members to format.
@@ -74,7 +91,7 @@ function formatSponsors(sponsors) {
7491 ${
7592 nonEmptySponsors . map ( tier => `<h3>${ tier [ 0 ] . toUpperCase ( ) } ${ tier . slice ( 1 ) } Sponsors</h3>
7693 <p>${
77- sponsors [ tier ] . map ( sponsor => `<a href="${ sponsor . url } "><img src="${ sponsor . image } " alt="${ sponsor . name } " height="${ heights [ tier ] } "></a>` ) . join ( " " )
94+ sponsors [ tier ] . map ( sponsor => `<a href="${ sponsor . url || "#" } "><img src="${ sponsor . image } " alt="${ sponsor . name } " height="${ heights [ tier ] } "></a>` ) . join ( " " )
7895 } </p>`) . join ( "" )
7996 }
8097 <!--sponsorsend-->` ;
@@ -111,20 +128,38 @@ const HTML_TEMPLATE = stripIndents`
111128
112129 <%- formatTeamMembers(team.committers) %>
113130
131+ <% } %>
132+
133+ <% if (team.website.length > 0) { %>
134+ ### Website Team
135+
136+ Team members who focus specifically on eslint.org
137+
138+ <%- formatTeamMembers(team.website) %>
139+
114140 <% } %>
115141 <!--teamend-->
116142` ;
117143
118- // replace all of the section
119- let newReadme = readme . replace ( / < ! - - t e a m s t a r t - - > [ \w \W ] * ?< ! - - t e a m e n d - - > / u, ejs . render ( HTML_TEMPLATE , {
120- team,
121- formatTeamMembers
122- } ) ) ;
144+ ( async ( ) => {
145+
146+ const [ allSponsors , team ] = await Promise . all ( [
147+ fetchSponsorsData ( ) ,
148+ fetchTeamData ( )
149+ ] ) ;
150+
151+ // replace all of the section
152+ let newReadme = readme . replace ( / < ! - - t e a m s t a r t - - > [ \w \W ] * ?< ! - - t e a m e n d - - > / u, ejs . render ( HTML_TEMPLATE , {
153+ team,
154+ formatTeamMembers
155+ } ) ) ;
156+
157+ newReadme = newReadme . replace ( / < ! - - s p o n s o r s s t a r t - - > [ \w \W ] * ?< ! - - s p o n s o r s e n d - - > / u, formatSponsors ( allSponsors ) ) ;
123158
124- newReadme = newReadme . replace ( / < ! - - s p o n s o r s s t a r t - - > [ \w \W ] * ?< ! - - s p o n s o r s e n d - - > / u, formatSponsors ( allSponsors ) ) ;
159+ // replace multiple consecutive blank lines with just one blank line
160+ newReadme = newReadme . replace ( / (?< = ^ | \n ) \n { 2 , } / gu, "\n" ) ;
125161
126- // replace multiple consecutive blank lines with just one blank line
127- newReadme = newReadme . replace ( / (?< = ^ | \n ) \n { 2 , } / gu , "\n " ) ;
162+ // output to the file
163+ fs . writeFileSync ( README_FILE_PATH , newReadme , "utf8 " ) ;
128164
129- // output to the file
130- fs . writeFileSync ( README_FILE_PATH , newReadme , "utf8" ) ;
165+ } ) ( ) ;
0 commit comments