From cac8847d651eaf4bf945c89480c7d12c9cf0ad12 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sun, 6 Oct 2024 11:36:24 +0200 Subject: [PATCH] docs: Add sponsors to README (#36) * docs: Add sponsors to README * remove IIFE --- .github/workflows/update-readme.yml | 34 ++++++++++++++++++ README.md | 19 +++++++--- package.json | 2 ++ tools/commit-readme.sh | 18 ++++++++++ tools/update-readme.js | 55 +++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/update-readme.yml create mode 100644 tools/commit-readme.sh create mode 100644 tools/update-readme.js diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml new file mode 100644 index 0000000..d15b4ee --- /dev/null +++ b/.github/workflows/update-readme.yml @@ -0,0 +1,34 @@ +name: Data Fetch + +on: + schedule: + - cron: "0 8 * * *" # Every day at 1am PDT + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out repo + uses: actions/checkout@v4 + with: + token: ${{ secrets.WORKFLOW_PUSH_BOT_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + + - name: Install npm packages + run: npm install + + - name: Update README with latest sponsor data + run: npm run build:readme + + - name: Setup Git + run: | + git config user.name "GitHub Actions Bot" + git config user.email "" + + - name: Save updated files + run: | + chmod +x ./tools/commit-readme.sh + ./tools/commit-readme.sh diff --git a/README.md b/README.md index 8795a1b..342c41c 100644 --- a/README.md +++ b/README.md @@ -208,11 +208,20 @@ Any other rules that catch potential problems in JSON are welcome to be implemen Apache 2.0 -## Sponsors - - - - +## 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

+ diff --git a/package.json b/package.json index dc2264f..1499353 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "build:dedupe-types": "node tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js", "build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"", "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", + "build:readme": "node tools/update-readme.js", "test:jsr": "npx jsr@latest publish --dry-run", "pretest": "npm run build", "lint": "eslint", @@ -71,6 +72,7 @@ "dedent": "^1.5.3", "eslint": "^9.11.1", "eslint-config-eslint": "^11.0.0", + "got": "^14.4.2", "lint-staged": "^15.2.7", "mocha": "^10.4.0", "prettier": "^3.3.2", diff --git a/tools/commit-readme.sh b/tools/commit-readme.sh new file mode 100644 index 0000000..dcbc986 --- /dev/null +++ b/tools/commit-readme.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#------------------------------------------------------------------------------ +# Commits the data files if any have changed +#------------------------------------------------------------------------------ + +if [ -z "$(git status --porcelain)" ]; then + echo "Data did not change." +else + echo "Data changed!" + + # commit the result + git add README.md + git commit -m "docs: Update README sponsors" + + # push back to source control + git push origin HEAD +fi diff --git a/tools/update-readme.js b/tools/update-readme.js new file mode 100644 index 0000000..0420068 --- /dev/null +++ b/tools/update-readme.js @@ -0,0 +1,55 @@ +/** + * @fileoverview Script to update the README with sponsors details in all packages. + * + * node tools/update-readme.js + * + * @author Milos Djermanovic + */ + +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + +import { readFileSync, writeFileSync } from "node:fs"; +import got from "got"; + +//----------------------------------------------------------------------------- +// Data +//----------------------------------------------------------------------------- + +const SPONSORS_URL = + "https://raw.githubusercontent.com/eslint/eslint.org/main/includes/sponsors.md"; + +const README_FILE_PATH = "./README.md"; + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- + +/** + * Fetches the latest sponsors from the website. + * @returns {Promise}} Prerendered sponsors markdown. + */ +async function fetchSponsorsMarkdown() { + return got(SPONSORS_URL).text(); +} + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- + +const allSponsors = await fetchSponsorsMarkdown(); + +// read readme file +const readme = readFileSync(README_FILE_PATH, "utf8"); + +let newReadme = readme.replace( + /[\w\W]*?/u, + `\n\n${allSponsors}\n`, +); + +// replace multiple consecutive blank lines with just one blank line +newReadme = newReadme.replace(/(?<=^|\n)\n{2,}/gu, "\n"); + +// output to the files +writeFileSync(README_FILE_PATH, newReadme, "utf8");