From 199a51c2443a50dca0c5ffd5279a640358b1ed2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= Date: Tue, 23 Jan 2024 20:44:04 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20generate=20markdown=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/json.yml | 23 +++++- README.md | 132 ++++++++++++++++++++++----------- TODO.md | 2 +- eslint.config.js | 4 +- json/eemoji-config-schema.json | 1 + package.json | 5 +- pnpm-lock.yaml | 45 +++++++++++ scripts/readme-table.ts | 59 +++++++++++++++ scripts/schema.ts | 7 +- src/emojis.jsonc | 56 ++++++++++++++ 10 files changed, 285 insertions(+), 49 deletions(-) create mode 100644 src/emojis.jsonc diff --git a/.github/workflows/json.yml b/.github/workflows/json.yml index fe7ce7d..f84c39e 100644 --- a/.github/workflows/json.yml +++ b/.github/workflows/json.yml @@ -7,7 +7,7 @@ on: branches: [main] paths: - src/config.ts - - src/emojis.json + - src/emojis.jsonc # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -33,6 +33,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + token: ${{ secrets.BOT_PAT }} - name: Install pnpm uses: pnpm/action-setup@v2 @@ -46,8 +48,17 @@ jobs: - name: Install run: pnpm i --ignore-scripts + - name: Build eemoji + run: pnpm run build + + - name: Setup eemoji + run: pnpm run postinstall + - name: Generate Schema - run: pnpm run schema + run: pnpm run gen:schema + + - name: Generate Markdown table + run: pnpm run gen:table - name: Setup Pages uses: actions/configure-pages@v3 @@ -58,6 +69,14 @@ jobs: # only upload the eemoji-config-schema.json file path: json + - name: Push changes + run: | + git config --local user.email "eemoji-bot@users.noreply.github.com" + git config --local user.name "eemoji-bot" + git add . + git commit -m "Update JSON schema" -a + git push + - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v2 diff --git a/README.md b/README.md index ede772a..9cc19b4 100644 --- a/README.md +++ b/README.md @@ -21,46 +21,51 @@ Hi, read the `README.md` first (starting with [Install](#-install)). This emoji
Close/open gigantic table -| Type | Subtype | Emoji | Description | -| ---- | ------- | ----- | ----------- | -| `fix` | `.` | πŸ”§ | general fix | -| `fix` | `typo` | ✏️ | fixed typo in code, docs, ui, etc. | -| `fix` | `bug` | πŸ› | fixed a bug | -| `chore` | `.` | πŸ—‘οΈ | did some chores | -| `chore` | `release` | πŸ”– | new release commit (pairs well with [bumpp](https://github.com/antfu/bumpp)) | -| `chore` | `cleanup` | 🧹 | cleaned up code, removed logs and debug stuff, making things ready for production | -| `chore` | `license` | πŸ“œ | changed the license | -| `chore` | `lint` | 🧼 | fixed linting errors | -| `chore` | `deps` | πŸ“¦ | updated dependencies | -| `chore` | `readme` | πŸ“•,πŸ“—,πŸ“˜,πŸ“™ | update the README | -| `release` | | πŸ”– | | -| `cleanup` | | 🧹 | | -| `lint` | | 🧼 | | -| `deps` | `.` | πŸ“¦ | added/removed/changed dependencies | -| `deps` | `up` | ⬆️ | updated dependencies | -| `deps` | `down` | ⬇️ | downgraded dependencies | -| `build` | `.` | 🦺 | work regarding build processes | -| `build` | `deps` | πŸ“¦ | dependabot PRs | -| `docs` | `.` | πŸ“ | documented something | -| `docs` | `readme` | πŸ“•,πŸ“—,πŸ“˜,πŸ“™ | | -| `feat` | `.` | ✨ | introduced a new feature | -| `feat` | `enhance` | πŸ’Ž | made something a little better (but still include in release notes) | -| `enhance` | | πŸ’Ž | made something a little better (omit from release notes) | -| `test` | | πŸ§ͺ | worked on tests | -| `refactor` | | ♻️ | refactored code, achieved the same with less | -| `init` | `initial` | | πŸŽ‰ | started a new project! | -| `perf` | | ⚑ | improved performance, achieve the same faster | -| `config` | | βš™οΈ | changed configuration files | -| `style` | | 🎨 | design changes, style changes | -| `ui` | | πŸͺŸ | worked on UI, UX or layout | -| `text` | | πŸ’¬ | changed string literals, text content | -| `breaking` | | πŸ’₯ | *special type:* will be used if the commit contains an exclamation mark (`!`), indicates breaking changes | -| `revert` | | βͺ | revert a commit | -| `ci` | | 🦾 | changed workflow files, CI stuff | -| `i18n` | | 🌐 | translated something | -| `wip` | | 🚧 | wildcard type, works for anything | -| `add` | | βž• | | -| `remove` | | βž– | | + +| Type | Subtype | Emoji | Description | +| -------------- | --------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| `fix` | `.` | πŸ”§ | general fix | +| `fix` | `typo` | ✏️ | fixed typo in code, docs, ui, etc. | +| `fix` | `bug` | πŸ› | fixed a bug | +| `chore` | `.` | πŸ—‘οΈ | did some chores | +| `chore` | `release` | πŸ”– | new release commit (pairs well with [bumpp](https://github.com/antfu/bumpp)) | +| `chore` | `cleanup` | 🧹 | cleaned up code, removed logs and debug stuff, made everyting ready for production | +| `chore` | `license` | πŸ“œ | changed the license | +| `chore` | `lint` | 🧼 | fixed linting errors | +| `chore` | `deps` | πŸ“¦ | changed dependencies | +| `chore` | `readme` | πŸ“•,πŸ“—,πŸ“˜,πŸ“™ | update the README | +| `release` | | πŸ”– | | +| `cleanup` | | 🧹 | | +| `lint` | | 🧼 | | +| `deps` | `.` | πŸ“¦ | added/removed/changed dependencies | +| `deps` | `up` | ⬆️ | updated dependencies | +| `deps` | `down` | ⬇️ | downgraded dependencies | +| `build` | `.` | 🦺 | work regarding build processes | +| `build` | `deps` | πŸ“¦ | dependabot PRs (see the prefix in the [dependabot.yml](./.github/dependabot.yml) file on how to add an emoji to our friend's PRs) | +| `docs` | `.` | πŸ“ | documented something | +| `docs` | `readme` | πŸ“•,πŸ“—,πŸ“˜,πŸ“™ | | +| `feat` | `.` | ✨ | introduced a new feature | +| `feat` | `enhance` | πŸ’Ž | made something a little better (but still include in release notes) | +| `enhance` | | πŸ’Ž | made something a little better (omit from release notes) | +| `test` | | πŸ§ͺ | worked on tests | +| `refactor` | | ♻️ | refactored code, achieved the same with less | +| `init|initial` | | πŸŽ‰ | started a new project! | +| `up` | | ⬆️ | | +| `down` | | ⬇️ | | +| `perf` | | ⚑ | improved performance, achieved the same faster | +| `config` | | βš™οΈ | changed configuration files | +| `security` | | πŸ”’ | | +| `style` | | 🎨 | design changes, style changes | +| `ui` | | πŸͺŸ | worked on UI, UX or layout | +| `text` | | πŸ’¬ | changed string literals, text content | +| `breaking` | | πŸ’₯ | *special type:* will be used if the commit contains an exclamation mark (`!`), indicates breaking changes | +| `revert` | | βͺ | revert a commit | +| `ci` | | 🦾 | changed workflow files, CI stuff | +| `i18n` | | 🌐 | translated something | +| `wip` | | 🚧 | wildcard type, works for anything | +| `add` | | βž• | | +| `remove` | | βž– | | +
@@ -161,7 +166,7 @@ eemoji run ## 🦾 Config -The default configuration is here: [emojis.json](./src/emojis.json) and the [Emojis](#-emojis) section. +The default configuration is here: [emojis.jsonc](./src/emojis.jsonc) and the [Emojis](#-emojis) section. This is used if no config file is found in the project. @@ -329,9 +334,52 @@ If it continues to fail to work, try this as well and restart everything: - Run this command once: `git config stash.usebuiltin false` +## 🀝 Contributing + +### Adding a new emoji + +To add a new emoji to the default config or modify it, please open an issue first. + +Then, if it's okay: + +- modify the [emojis.jsonc](./src/emojis.jsonc) file, add the emoji and a description +- The Action will take care of the rest (copying it to the json, updating the readme emoji table and the json schema) +- open a PR + +### Creating a new emoji preset + +SOONℒ️ + +### Development + +> [!TIP] +> Install pnpm and [ni](https://github.com/antfu/ni). +> +> ```bash +> npm i -g pnpm @antfu/ni +> ``` + +```bash +ni +``` + +Use the `stub` script to run have the latest changes build: + +```bash +nr stub +``` + +Run commands with the `dev` script: + +```bash +nr dev +``` + +Also check the [TODO](./TODO.md) file and open an issue first if you want to work on something. + ## πŸ’› Badge -[![eemoji](https://img.shields.io/badge/😎%20eemoji-fccf1d?style=for-the-badge)]( https://github.com/Rettend/eemoji) +[![eemoji](https://img.shields.io/badge/😎%20eemoji-fccf1d?style=for-the-badge)](https://github.com/Rettend/eemoji) ```md [![eemoji](https://img.shields.io/badge/😎%20eemoji-fccf1d?style=for-the-badge)]( diff --git a/TODO.md b/TODO.md index 9021e0b..9d9d28d 100644 --- a/TODO.md +++ b/TODO.md @@ -16,5 +16,5 @@ - [x] make the consola start and success logs sane in the cleanup command - [x] investigate speed, prepare script for init - [x] move bin scripts to `scripts` folder and also build them from typescript -- [ ] Generate the readme emoji table from `emojis.json` (jsonc for description) +- [x] Generate the readme emoji table from `emojis.jsonc` (jsonc for description) - [ ] try astro and create a small website explaining which emoji to use and when, + stuff diff --git a/eslint.config.js b/eslint.config.js index 3b614a0..cfae2ac 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,3 +1,5 @@ import antfu from '@antfu/eslint-config' -export default antfu() +export default antfu({ + ignores: ['src/**/*.jsonc'], +}) diff --git a/json/eemoji-config-schema.json b/json/eemoji-config-schema.json index e712590..2bf7d32 100644 --- a/json/eemoji-config-schema.json +++ b/json/eemoji-config-schema.json @@ -72,6 +72,7 @@ "down": "⬇️", "perf": "⚑", "config": "βš™οΈ", + "security": "πŸ”’", "style": "🎨", "ui": "πŸͺŸ", "text": "πŸ’¬", diff --git a/package.json b/package.json index c023d1d..07502d0 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "typecheck": "tsc --noEmit", - "schema": "tsx scripts/schema", + "gen:schema": "tsx scripts/schema", + "gen:table": "tsx scripts/readme-table", "release": "bumpp && unbuild && pnpm publish", "postinstall": "node ./bin/eemoji.mjs init -c none", "preuninstall": "node ./bin/eemoji.mjs cleanup", @@ -63,9 +64,11 @@ "@vitest/coverage-istanbul": "^1.2.1", "@vitest/ui": "^1.2.1", "bumpp": "^9.2.0", + "comment-json": "^4.2.3", "eemoji": "^1.1.5", "eslint": "^8.56.0", "lint-staged": "^15.2.0", + "markdown-table": "^3.0.3", "simple-git-hooks": "^2.9.0", "tsx": "^4.7.0", "typescript": "5.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 078978b..221ab7f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,6 +43,9 @@ devDependencies: bumpp: specifier: ^9.2.0 version: 9.3.0 + comment-json: + specifier: ^4.2.3 + version: 4.2.3 eemoji: specifier: ^1.1.5 version: 1.1.5(typescript@5.3.3) @@ -52,6 +55,9 @@ devDependencies: lint-staged: specifier: ^15.2.0 version: 15.2.0 + markdown-table: + specifier: ^3.0.3 + version: 3.0.3 simple-git-hooks: specifier: ^2.9.0 version: 2.9.0 @@ -1382,6 +1388,10 @@ packages: /argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} + /array-timsort@1.0.3: + resolution: {integrity: sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==} + dev: true + /array-union@2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} @@ -1671,6 +1681,17 @@ packages: engines: {node: '>= 10'} dev: true + /comment-json@4.2.3: + resolution: {integrity: sha512-SsxdiOf064DWoZLH799Ata6u7iV658A11PlWtZATDlXPpKGJnbJZ5Z24ybixAi+LUUqJ/GKowAejtC5GFUG7Tw==} + engines: {node: '>= 6'} + dependencies: + array-timsort: 1.0.3 + core-util-is: 1.0.3 + esprima: 4.0.1 + has-own-prop: 2.0.0 + repeat-string: 1.6.1 + dev: true + /comment-parser@1.4.1: resolution: {integrity: sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg==} engines: {node: '>= 12.0.0'} @@ -1698,6 +1719,10 @@ packages: browserslist: 4.22.2 dev: true + /core-util-is@1.0.3: + resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} + dev: true + /cosmiconfig@8.3.6(typescript@5.3.3): resolution: {integrity: sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==} engines: {node: '>=14'} @@ -2433,6 +2458,12 @@ packages: eslint-visitor-keys: 3.4.3 dev: true + /esprima@4.0.1: + resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} + engines: {node: '>=4'} + hasBin: true + dev: true + /esquery@1.5.0: resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} engines: {node: '>=0.10'} @@ -2736,6 +2767,11 @@ packages: engines: {node: '>=8'} dev: true + /has-own-prop@2.0.0: + resolution: {integrity: sha512-Pq0h+hvsVm6dDEa8x82GnLSYHOzNDt7f0ddFa3FqcQlgzEiptPqL+XrOJNavjOzSYiYWIrgeVYYgGlLmnxwilQ==} + engines: {node: '>=8'} + dev: true + /hasown@2.0.0: resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==} engines: {node: '>= 0.4'} @@ -3174,6 +3210,10 @@ packages: semver: 7.5.4 dev: true + /markdown-table@3.0.3: + resolution: {integrity: sha512-Z1NL3Tb1M9wH4XESsCDEksWoKTdlUafKc4pt0GRwjUyXaCFZ+dc3g2erqB6zm3szA2IUSi7VnPI+o/9jnxh9hw==} + dev: true + /mdast-util-from-markdown@0.8.5: resolution: {integrity: sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==} dependencies: @@ -3979,6 +4019,11 @@ packages: jsesc: 0.5.0 dev: true + /repeat-string@1.6.1: + resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==} + engines: {node: '>=0.10'} + dev: true + /require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} diff --git a/scripts/readme-table.ts b/scripts/readme-table.ts index e69de29..a024b38 100644 --- a/scripts/readme-table.ts +++ b/scripts/readme-table.ts @@ -0,0 +1,59 @@ +import fs from 'node:fs' +import process from 'node:process' +import path from 'node:path' +import type { + CommentArray, + CommentDescriptor, + CommentJSONValue, + CommentSymbol, +} from 'comment-json' +import { parse } from 'comment-json' +import { markdownTable } from 'markdown-table' +import emojis from '../src/emojis.json' + +const cwd = process.env.INIT_CWD || process.cwd() +const eemojiPath = path.join(cwd, 'src/emojis.jsonc') +const readmePath = path.join(cwd, 'README.md') + +const emojiFile = fs.readFileSync(eemojiPath, 'utf8') +const emojiJsonc = parse(emojiFile) + +if (!emojiJsonc) { + console.error('Failed to parse emojis.jsonc') + process.exit(1) +} + +const table = [['Type', 'Subtype', 'Emoji', 'Description']] + +for (const key in emojis) { + if (typeof emojis[key] === 'object') { + for (const subKey in emojis[key]) { + const description = getDescription(emojiJsonc[key], subKey) + table.push([`\`${key}\``, `\`${subKey}\``, emojis[key][subKey], description]) + } + } + else { + const description = getDescription(emojiJsonc, key) + table.push([`\`${key}\``, '', emojis[key], description]) + } +} + +function getDescription(object: CommentJSONValue, key: string) { + if (!object) + return '' + + const commentArray = object as CommentArray + const symbolName: CommentDescriptor = `after:${key}` + + const comment = commentArray[Symbol.for(symbolName) as CommentSymbol] + return comment ? comment[0].value : '' +} + +const markdown = markdownTable(table) + +let readmeContent = fs.readFileSync(readmePath, 'utf8') +readmeContent = readmeContent.replace( + /[\s\S]*/, + `\n${markdown}\n`, +) +fs.writeFileSync(readmePath, readmeContent) diff --git a/scripts/schema.ts b/scripts/schema.ts index e124e3d..39840f7 100644 --- a/scripts/schema.ts +++ b/scripts/schema.ts @@ -1,7 +1,10 @@ import fs from 'node:fs' +import * as jsonc from 'jsonc-parser' import schema from './../json/eemoji-config-schema.json' -import emojis from './../src/emojis.json' -schema.properties.emojis.default = emojis +const emojis = jsonc.parse(fs.readFileSync('./src/emojis.jsonc', 'utf8')) +schema.properties.emojis.default = emojis fs.writeFileSync('./json/eemoji-config-schema.json', `${JSON.stringify(schema, null, 2)}\n`) + +fs.writeFileSync('./src/emojis.json', `${JSON.stringify(emojis, null, 2)}\n`) diff --git a/src/emojis.jsonc b/src/emojis.jsonc new file mode 100644 index 0000000..277b548 --- /dev/null +++ b/src/emojis.jsonc @@ -0,0 +1,56 @@ + +{ + "fix": { + ".": "πŸ”§", // general fix + "typo": "✏️", // fixed typo in code, docs, ui, etc. + "bug": "πŸ›", // fixed a bug + "security": "πŸ”’" // fixed security issues + }, + "chore": { + ".": "πŸ—‘οΈ", // did some chores + "release": "πŸ”–", // new release commit (pairs well with [bumpp](https://github.com/antfu/bumpp)) + "cleanup": "🧹", // cleaned up code, removed logs and debug stuff, made everyting ready for production + "license": "πŸ“œ", // changed the license + "lint": "🧼", // fixed linting errors + "deps": "πŸ“¦", // changed dependencies + "readme": "πŸ“•,πŸ“—,πŸ“˜,πŸ“™" // update the README + }, + "release": "πŸ”–", + "cleanup": "🧹", + "lint": "🧼", + "deps": { + ".": "πŸ“¦", // added/removed/changed dependencies + "up": "⬆️", // updated dependencies + "down": "⬇️" // downgraded dependencies + }, + "up": "⬆️", + "down": "⬇️", + "build": { + ".": "🦺", // work regarding build processes + "deps": "πŸ“¦" // dependabot PRs (see the prefix in the [dependabot.yml](./.github/dependabot.yml) file on how to add an emoji to our friend's PRs) + }, + "docs": { + ".": "πŸ“", // documented something + "readme": "πŸ“•,πŸ“—,πŸ“˜,πŸ“™" + }, + "feat": { + ".": "✨", // introduced a new feature + "enhance": "πŸ’Ž" // made something a little better (but still include in release notes) + }, + "enhance": "πŸ’Ž", // made something a little better (omit from release notes) + "test": "πŸ§ͺ", // worked on tests + "refactor": "♻️", // refactored code, achieved the same with less + "init|initial": "πŸŽ‰", // started a new project! + "perf": "⚑", // improved performance, achieved the same faster + "breaking": "πŸ’₯", // *special type:* will be used if the commit contains an exclamation mark (`!`), indicates breaking changes + "ci": "🦾", // changed workflow files, CI stuff + "config": "βš™οΈ", // changed configuration files + "style": "🎨", // design changes, style changes + "ui": "πŸͺŸ", // worked on UI, UX or layout + "text": "πŸ’¬", // changed string literals, text content + "revert": "βͺ", // revert a commit + "i18n": "🌐", // translated something + "wip": "🚧", // wildcard type, works for anything + "add": "βž•", + "remove": "βž–" +}