diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000..7b910fae2 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,7 @@ +# Run lint and abort if there are any lint errors +# --quiet will supress warnings which would cause this check to fail too +# this is temporary until all warnings are fixed +npm run lint --quiet || exit 1 + +# Run format:check on modified and uncommitted files and abort if there are any formatting errors +npm run format:check --uncommitted || exit 1 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 0c76a2924..b009679ac 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -14,7 +14,6 @@ 1. Run `npm install` 1. Run `docker compose --env-file ./.env -f docker/docker-compose.dev.yml up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io) 1. Run `npm run database:setup` to initialize the database schema -1. Run `git config core.hooksPath ./git-hooks/` to setup git hooks 1. Start the [server](#start-server) and the [client](#start-client) 1. Open https://localhost:4200/en in your browser 1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`) diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit deleted file mode 100755 index b2b86eac1..000000000 --- a/git-hooks/pre-commit +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# Will check if "npm run format" is run before executing. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. - -echo "Running npm run format" - -# Run the command and loop over its output -FILES_TO_STAGE="" -i=0 -while IFS= read -r line; do - # Process each line here - ((i++)) - if [ $i -le 2 ]; then - continue - fi - if [[ $line == Done* ]]; then - break - fi - FILES_TO_STAGE="$FILES_TO_STAGE $line" - -done < <(npm run format) -git add $FILES_TO_STAGE -echo "Files formatted. Committing..." diff --git a/package-lock.json b/package-lock.json index b848e8188..cccecad7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -143,6 +143,7 @@ "eslint-plugin-cypress": "2.15.1", "eslint-plugin-import": "2.29.1", "eslint-plugin-storybook": "0.6.15", + "husky": "^9.1.6", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", "jest-preset-angular": "14.1.0", @@ -20653,6 +20654,21 @@ "node": ">=8.12.0" } }, + "node_modules/husky": { + "version": "9.1.6", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.6.tgz", + "integrity": "sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==", + "dev": true, + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/hyperdyperid": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/hyperdyperid/-/hyperdyperid-1.2.0.tgz", diff --git a/package.json b/package.json index 584407f1d..2600910f0 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "format:check": "nx format:check", "format:write": "nx format:write", "help": "nx help", - "lint": "nx lint", + "lint": "nx run-many --target=lint --all", "ng": "nx", "nx": "nx", "postinstall": "prisma generate", @@ -188,6 +188,7 @@ "eslint-plugin-cypress": "2.15.1", "eslint-plugin-import": "2.29.1", "eslint-plugin-storybook": "0.6.15", + "husky": "9.1.6", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", "jest-preset-angular": "14.1.0",