]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tools/update-readme.js
24fe3c01d2b3ecda426803c4912d4830eded7cf2
[pve-eslint.git] / eslint / tools / update-readme.js
1 /**
2 * @fileoverview Script to update the README with team and sponsors.
3 * Note that this requires eslint/website to be available in the same
4 * directory as the eslint repo.
5 *
6 * node tools/update-readme.js
7 *
8 * @author Nicholas C. Zakas
9 */
10 "use strict";
11
12 //-----------------------------------------------------------------------------
13 // Requirements
14 //-----------------------------------------------------------------------------
15
16 const path = require("path");
17 const fs = require("fs");
18 const { stripIndents } = require("common-tags");
19 const ejs = require("ejs");
20
21 //-----------------------------------------------------------------------------
22 // Data
23 //-----------------------------------------------------------------------------
24
25 const README_FILE_PATH = path.resolve(__dirname, "../README.md");
26 const WEBSITE_DATA_PATH = path.resolve(__dirname, "../../website/_data");
27
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")));
30 const readme = fs.readFileSync(README_FILE_PATH, "utf8");
31
32 const heights = {
33 gold: 96,
34 silver: 64,
35 bronze: 32
36 };
37
38 // remove backers from sponsors list - not shown on readme
39 delete allSponsors.backers;
40
41 //-----------------------------------------------------------------------------
42 // Helpers
43 //-----------------------------------------------------------------------------
44
45 /**
46 * Formats an array of team members for inclusion in the readme.
47 * @param {Array} members The array of members to format.
48 * @returns {string} The HTML for the members list.
49 */
50 function formatTeamMembers(members) {
51 /* eslint-disable indent*/
52 return stripIndents`
53 <table><tbody><tr>${
54 members.map((member, index) => `<td align="center" valign="top" width="11%">
55 <a href="https://github.com/${member.username}">
56 <img src="https://github.com/${member.username}.png?s=75" width="75" height="75"><br />
57 ${member.name}
58 </a>
59 </td>${(index + 1) % 9 === 0 ? "</tr><tr>" : ""}`).join("")
60 }</tr></tbody></table>`;
61 /* eslint-enable indent*/
62 }
63
64 /**
65 * Formats an array of sponsors into HTML for the readme.
66 * @param {Array} sponsors The array of sponsors.
67 * @returns {string} The HTML for the readme.
68 */
69 function formatSponsors(sponsors) {
70 const nonEmptySponsors = Object.keys(sponsors).filter(tier => sponsors[tier].length > 0);
71
72 /* eslint-disable indent*/
73 return stripIndents`<!--sponsorsstart-->
74 ${
75 nonEmptySponsors.map(tier => `<h3>${tier[0].toUpperCase()}${tier.slice(1)} Sponsors</h3>
76 <p>${
77 sponsors[tier].map(sponsor => `<a href="${sponsor.url}"><img src="${sponsor.image}" alt="${sponsor.name}" height="${heights[tier]}"></a>`).join(" ")
78 }</p>`).join("")
79 }
80 <!--sponsorsend-->`;
81 /* eslint-enable indent*/
82 }
83
84 //-----------------------------------------------------------------------------
85 // Main
86 //-----------------------------------------------------------------------------
87
88 const HTML_TEMPLATE = stripIndents`
89
90 <!--teamstart-->
91
92 ### Technical Steering Committee (TSC)
93
94 The people who manage releases, review feature requests, and meet regularly to ensure ESLint is properly maintained.
95
96 <%- formatTeamMembers(team.tsc) %>
97
98 <% if (team.reviewers.length > 0) { %>
99 ### Reviewers
100
101 The people who review and implement new features.
102
103 <%- formatTeamMembers(team.reviewers) %>
104
105 <% } %>
106
107 <% if (team.committers.length > 0) { %>
108 ### Committers
109
110 The people who review and fix bugs and help triage issues.
111
112 <%- formatTeamMembers(team.committers) %>
113
114 <% } %>
115 <!--teamend-->
116 `;
117
118 // replace all of the section
119 let newReadme = readme.replace(/<!--teamstart-->[\w\W]*?<!--teamend-->/u, ejs.render(HTML_TEMPLATE, {
120 team,
121 formatTeamMembers
122 }));
123
124 newReadme = newReadme.replace(/<!--sponsorsstart-->[\w\W]*?<!--sponsorsend-->/u, formatSponsors(allSponsors));
125
126 // output to the file
127 fs.writeFileSync(README_FILE_PATH, newReadme, "utf8");