From 5c5da263068cfe849af8e6530e7cc45fea7da209 Mon Sep 17 00:00:00 2001 From: scosman Date: Thu, 29 Aug 2024 14:19:44 -0400 Subject: [PATCH] Adding ./checks.sh for contributors, and easier dev-tool setup --- README.md | 35 +++++++++++++++++++++++------------ checks.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 12 deletions(-) create mode 100755 checks.sh diff --git a/README.md b/README.md index 73720aff..2718e3a4 100644 --- a/README.md +++ b/README.md @@ -161,9 +161,22 @@ npm run dev -- --open ## Developer Tools -The repo includes [CI scripts](https://aws.amazon.com/devops/continuous-integration/) designed for [GitHub Actions](https://github.com/features/actions). These confirm you don’t break your [build](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/build.yml), you use [proper code formatting](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/format.yml), and [code linting and typechecking passes](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/linting.yml). Github disables CI on new repos by default, so be sure to go into the Github Actions page for your repo and enable workflows. +The repo includes [CI scripts](https://aws.amazon.com/devops/continuous-integration/) designed for [GitHub Actions](https://github.com/features/actions). These confirm you don’t break your [build](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/build.yml), you use [proper code formatting](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/format.yml), [code linting and typechecking passes](https://github.com/CriticalMoments/CMSaasStarter/blob/main/.github/workflows/linting.yml), and even spell checking. -You can manually run these scripts yourself; `npm run build` for the build, `npm run format_check` to check formatting, `npm run lint` for the linting, `npm run check` for typechecking, and `npm run test` for testing (if you add tests). +### Enabling GitHub Actions + +Github disables CI on new forks by default, so be sure to go into the Github Actions page for your repo and enable workflows. + +### Running Developer Tools Locally + +To manually run all these tools run the following script. You can view it's contents for individual commands. + +``` +# first time only: chmod +x ./check.sh +./check.sh +``` + +### Running Developer Tools in your IDE Installing extensions in your editor can automatically format-on-save, show linting/type issues inline, and run your test cases: @@ -171,22 +184,20 @@ Installing extensions in your editor can automatically format-on-save, show lint - ESLint for type checking and linting: [VSCode](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [other editors](https://eslint.org/docs/latest/use/integrations) - Vitest for testing if you add tests: [VSCode](https://marketplace.visualstudio.com/items?itemName=vitest.explorer) or [other editors](https://vitest.dev/guide/ide) +### Running Developer Tools from Git Hooks + To catch build, formatting, linting and test issues before you commit changes, we suggest the following local git hook. It will run before you commit, stop you from breaking the build, and show any issues that are found. Add the lines below to an executable git hook script at the location `.git/hooks/pre-commit`. ``` #!/bin/sh -set -e -npm run format_check -npm run lint -npm run build -npm run check -npm run test_run - -# Optional: check for misspelled words. Uncomment line below after installing misspell tool https://github.com/client9/misspell?tab=readme-ov-file#install -# misspell -error ./src README.md +# Run standard checks before committing +cd "$(dirname "$0")" +sh ../../checks.sh ``` -Finally: if you find build, formatting or linting rules too tedious, you can disable enforcement by deleting the CI files (`.github/workflows/*`) and remove the git hook (`.git/hooks/pre-commit`). +### Disabling Developer Tools + +If you find build, formatting or linting rules too tedious, you can disable enforcement by deleting the CI files (`.github/workflows/*`) and removing the git hook (`.git/hooks/pre-commit`). ## Setup Supabase Project diff --git a/checks.sh b/checks.sh new file mode 100755 index 00000000..2f7e994d --- /dev/null +++ b/checks.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# error on first error +set -e + +if ! command -v misspellx &> /dev/null +then + echo "=== Skipping Spell Check ===" + echo "Skip running spell check using 'misspell' as the tool is not installed." + echo "Install it using the instructions here: https://github.com/client9/misspell" + echo "Skipping this check now, but it may fail in CI.\n" +else + echo "=== Running Spell Check ===" + misspell -error ./src README.md + echo "no spelling mistakes found\n" +fi + +echo "=== Running Format Check With Prettier ===" +npm run format_check + +echo "=== Running Linter ===" +npm run lint + +echo "=== Running Svelte Check ===" +npm run check + +echo "=== Running Tests ===" +npm run test_run + +echo "\n=== All Checks Pass ===\n" +