From 32d6a1f78d2199f35faa0d6914d233b7377fea26 Mon Sep 17 00:00:00 2001 From: Mathys-Gasnier Date: Thu, 2 Jan 2025 12:40:23 +0100 Subject: [PATCH] Adding scripts to check and consolidate snippets, fix the workflow failing if snippets were already consolidated. --- .github/workflows/consolidate-snippets.yml | 2 +- CONTRIBUTING.md | 14 +++++++++++++- README.md | 13 +++++++++++++ package.json | 4 +++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/consolidate-snippets.yml b/.github/workflows/consolidate-snippets.yml index 207013bb..a252a721 100644 --- a/.github/workflows/consolidate-snippets.yml +++ b/.github/workflows/consolidate-snippets.yml @@ -35,5 +35,5 @@ jobs: git config --global user.email "action@github.com" git add public/consolidated/* git add public/icons/* - git commit -m "Update consolidated snippets" + git diff-index --quiet HEAD || git commit -m "Update consolidated snippets" git push diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 233a5247..3d2503c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -79,7 +79,19 @@ console.log(formatDate(new Date())); // Output: '2024-12-10' - Specify the language after the first set of backticks for syntax highlighting. 6. **Test your snippet:** - - Ensure your code runs as expected. + - Ensure your code runs as expected. \ + To test that your snippets are formatted correctly use the `snippets:check` script: + ``` + $ npm run snippets:check + ``` + It will return nothing if they are well formatted, otherwise it will tell you what the error is. + + --- + To preview the snippets, you need to consolidate them, use the `snippets:consolidate` script: + ``` + $ npm run snippets:consolidate + ``` + It will update the snippets in the `/public` folder, making them available to the frontend. Expected file structure: diff --git a/README.md b/README.md index 39eacd67..d06e4955 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,19 @@ Expected file structure: > Please do **NOT** add or edit anything in `/public` folder. It will be used for consolidating snippets. +To test that your snippets are formatted correctly use the `snippets:check` script: +``` +$ npm run snippets:check +``` +It will return nothing if they are well formatted, otherwise it will tell you what the error is. + +--- +To preview the snippets, you need to consolidate them, use the `snippets:consolidate` script: +``` +$ npm run snippets:consolidate +``` +It will update the snippets in the `/public` folder, making them available to the frontend. + For more details about adding new categories or programming languages, check out the [CONTRIBUTING.md](/CONTRIBUTING.md) file. ## Guidelines for Contributions diff --git a/package.json b/package.json index b21a3038..71d12cde 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "format": "prettier --write .", "format:check": "prettier --check .", "preview": "vite preview", - "prepare": "husky" + "prepare": "husky", + "snippets:check": "node ./utils/checkSnippetFormatting.js", + "snippets:consolidate": "node ./utils/consolidateSnippets.js" }, "dependencies": { "framer-motion": "^11.15.0",