j40-cejst-2/client/.husky/pre-commit
Vim 14ad8c2ee4
Add intl pre-commit hook and update GHA (#1416)
* Add intl pre-commit hook and update GHA

- add Husky lib
- add pre-commit script
- detect warning on extraction and abort commit
- update deploy staging yml to show message that en.json was modified

* Test if block of message post

- test if the message is posted even when checking a file with no changes

* Add back in full deploy action

* Add back en.json
2022-03-17 10:03:26 -07:00

41 lines
No EOL
1.4 KiB
Bash
Executable file

#!/bin/bash
echo
echo "[pre-commit hook msg]: running pre-commit hook ..."
# Husky by default expects pre-commit hooks in the root directory. We set up a custom directory for the client folder
# https://typicode.github.io/husky/#/?id=custom-directory
cd client
# This file will automatically run intl:extract and compile on every commit
# write the extracted errors into a file
npm run intl:extract 2> extract-err.txt
# check the extracted error files for warnings and abort commit if found
if grep -F "warning" extract-err.txt
then
echo
echo '[pre-commit hook msg]: ALERT: warnings found in extraction process. Please remove warnings and re-run "npm run intl:extract"'
echo
echo '[pre-commit hook msg]: aborting commit...'
echo
echo '[pre-commit hook msg]: removing extract-err file...'
echo
rm extract-err.txt
echo '[pre-commit hook msg]: pre-commit hook incomplete.'
echo
exit 1
else
echo
echo '[pre-commit hook msg]: no warnings found, continuing with commit ...'
echo
echo '[pre-commit hook msg]: removing extract-err file ...'
echo
rm extract-err.txt
echo '[pre-commit hook msg]: adding en.json to staging area ...'
echo
# add the en.json to staging so that the pre-commit hook can include it in the commit
git add src/intl/en.json
echo '[pre-commit hook msg]: pre-commit hook complete.'
echo
fi