From 3abc1cf6fdb587a3b36a7d7f9065ea04003c82e2 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sun, 6 Oct 2024 11:34:18 +0200 Subject: [PATCH] docs: Add sponsors to README (#287) * docs: Add sponsors to README * remove IIFE --- .github/workflows/update-readme.yml | 34 ++++++++++++++++++ README.md | 18 +++++++++- package.json | 2 ++ tools/commit-readme.sh | 18 ++++++++++ tools/update-readme.js | 55 +++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) 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 00000000..d15b4eea --- /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 d00ce478..7844afb9 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,6 @@ You can individually disable rules in Markdown using HTML comments, such as: | `commonmark` | Parse using [CommonMark](https://commonmark.org) Markdown format | | `gfm` | Parse using [GitHub-Flavored Markdown](https://github.github.com/gfm/) format | - In order to individually configure a language in your `eslint.config.js` file, import `@eslint/markdown` and configure a `language`: ```js @@ -152,3 +151,20 @@ $ npm test ``` This project follows the [ESLint contribution guidelines](https://eslint.org/docs/latest/contribute/). + + + + +## 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 8ff77f90..ed38c54c 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "build:rules": "node tools/build-rules.js", "build:update-rules-docs": "node tools/update-rules-docs.js", "build": "npm run build:rules && rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:update-rules-docs", + "build:readme": "node tools/update-readme.js", "prepare": "node ./npm-prepare.cjs && npm run build", "test": "c8 mocha \"tests/**/*.test.js\" --timeout 30000", "test:jsr": "npx jsr@latest publish --dry-run" @@ -68,6 +69,7 @@ "eslint": "^9.10.0", "eslint-config-eslint": "^11.0.0", "globals": "^15.1.0", + "got": "^14.4.2", "lint-staged": "^15.2.9", "mocha": "^10.6.0", "prettier": "^3.3.3", diff --git a/tools/commit-readme.sh b/tools/commit-readme.sh new file mode 100644 index 00000000..dcbc986b --- /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 00000000..0420068c --- /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");