From f923eff038f105ffa1828695e871e9ed5b323e19 Mon Sep 17 00:00:00 2001 From: Amaresh S M <30730124+amareshsm@users.noreply.github.com> Date: Fri, 25 Oct 2024 01:56:40 +0530 Subject: [PATCH 1/2] chore: Add sponsors to README --- README.md | 18 ++++++++++++++++ tools/generate-sponsors.js | 43 ++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 53b85a05c3..e05428f374 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,24 @@ In order to create a new translation: The ESLint team will create a new domain name, set up analytics and ads, and otherwise prepare the website for deployment. + + + +## Sponsors + +The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate) +to get your logo on our READMEs and [website](https://eslint.org/sponsors). + +

Platinum Sponsors

+

Automattic Airbnb

Gold Sponsors

+

trunk.io

Silver Sponsors

+

JetBrains Liftoff American Express Workleap

Bronze Sponsors

+

WordHint Anagram Solver Icons8 Discord GitBook Nx HeroCoders Nextbase Starter Kit

+

Technology Sponsors

+Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work. +

Netlify Algolia 1Password

+ + ## License [Apache 2.0](LICENSE) diff --git a/tools/generate-sponsors.js b/tools/generate-sponsors.js index dc81e36af0..b7f8948f2e 100644 --- a/tools/generate-sponsors.js +++ b/tools/generate-sponsors.js @@ -3,6 +3,7 @@ * This script generates a markdown file containing sponsor information. * It fetches sponsor data from specified JSON files, formats * the data into HTML sections, and writes the output to a new markdown file. + * Additionally, it updates the README file with the latest sponsor information. * * Usage: * Run the script using Node.js: @@ -51,6 +52,8 @@ The following companies, organizations, and individuals support ESLint's ongoing to get your logo on our READMEs and [website](https://eslint.org/sponsors). `; +const README_FILE_PATH = path.resolve(__dirname, "../README.md"); + //----------------------------------------------------------------------------- // Helpers //----------------------------------------------------------------------------- @@ -63,7 +66,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors). async function readData(filePath) { try { const data = await fs.readFile(filePath, "utf8"); - return JSON.parse(data); + return data; } catch (err) { console.error("Error reading or parsing the file:", err); return null; @@ -76,10 +79,11 @@ async function readData(filePath) { */ async function fetchSponsorsData() { const sponsorsData = await readData(SPONSORS_FILE_PATH); - if (sponsorsData) { - delete sponsorsData.backers; + const parsedSponsorData = JSON.parse(sponsorsData); + if (parsedSponsorData) { + delete parsedSponsorData.backers; } - return sponsorsData; + return parsedSponsorData; } /** @@ -87,7 +91,9 @@ async function fetchSponsorsData() { * @returns {Array|null} The tech sponsors data object. */ async function fetchTechSponsors() { - return readData(TECH_SPONSORS_FILE_PATH); + const sponsorsData = await readData(TECH_SPONSORS_FILE_PATH); + const parsedSponsorData = JSON.parse(sponsorsData); + return parsedSponsorData; } /** @@ -156,18 +162,37 @@ async function writeData(filePath, data) { } } +/** + * Updates the README file with the latest sponsors information. + * @param {string} sponsorsInfo The HTML string containing formatted sponsor information to be inserted. + * @returns {Promise} A promise that resolves when the update operation is complete. + */ +async function updateReadme(sponsorsInfo) { + const readme = await readData(README_FILE_PATH); + let newReadme = readme.replace( + /[\w\W]*?/u, + `\n\n${sponsorsInfo}\n`, + ); + + // replace multiple consecutive blank lines with just one blank line + newReadme = newReadme.replace(/(?<=^|\n)\n{2,}/gu, "\n"); + writeData(README_FILE_PATH, newReadme); +} + (async () => { - const [allSponsors, techSponsors] = await Promise.all([ + const [sponsors, techSponsors] = await Promise.all([ fetchSponsorsData(), fetchTechSponsors(), ]); - const newFileContent = stripIndents` + const allSponsors = stripIndents` ${SPONSOR_INTRO_TEXT} - ${formatSponsors(allSponsors)} + ${formatSponsors(sponsors)} ${formatTechSponsors(techSponsors)} `; - await writeData(NEW_FILE_PATH, newFileContent); + await writeData(NEW_FILE_PATH, allSponsors); console.log(`Sponsors information has been written to ${NEW_FILE_PATH}`); + + updateReadme(allSponsors); })(); From e19e2ae9c01061a67c4b861ff3bec5c90cc67128 Mon Sep 17 00:00:00 2001 From: Amaresh S M <30730124+amareshsm@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:20:24 +0530 Subject: [PATCH 2/2] Update commit-data.sh --- tools/commit-data.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/commit-data.sh b/tools/commit-data.sh index e735e3dd82..51748f0412 100644 --- a/tools/commit-data.sh +++ b/tools/commit-data.sh @@ -4,15 +4,15 @@ # Commits the data files if any have changed #------------------------------------------------------------------------------ -if [ -z "$(git status --porcelain)" ]; then +if [ -z "$(git status --porcelain)" ]; then echo "Data did not change." else echo "Data changed!" # commit the result - git add src/_data/ includes/ + git add src/_data/ includes/ README.md git commit -m "chore: Update remote data" # push back to source control - git push origin HEAD + git push origin HEAD fi