Skip to content

Commit

Permalink
chore: add husky for precommit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavsingh97 committed May 16, 2023
1 parent d641e5e commit 9f3c016
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

NORMAL=$(tput sgr0)
RED=$(tput setaf 1)

exec < /dev/tty

# Function to display a message with asterisks
display_box() {
local message="$1"
local length=${#message}

printf "\n"
printf "%0.s*" $(seq 1 $((length + 6)))
printf "\n"
printf "*${RED} %s ${NORMAL}*\n" "$message"
printf "%0.s*" $(seq 1 $((length + 6)))
printf "\n"
}

# Function to display staged files in a box
display_staged_files() {
local files=$(git diff --cached --name-only)
local file_count=$(echo $files | wc -l)
echo "+-------------------+\n"
echo "| Staged files |\n"
echo "+-------------------+\n"
if [ $file_count -gt 0 ]; then
git diff --cached --name-only | sed 's/^/| /;s/$/ |/'
else
echo "| No files |\n"
fi
echo "+-------------------+\n"
}

display_staged_files
echo "Did you add types for these changes?"
read -p "Enter your response (yes/no): " response


if [ "$response" != "yes" ]; then
display_box "Error: Types not added. Please add types before committing."
exit 1
fi
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"ts-node": "^10.9.1",
"tsd": "^0.28.1",
"typescript": "^4.8.4",
"wait-on": "^7.0.1"
"wait-on": "^7.0.1",
"husky": "^8.0.0"
},
"peerDependencies": {
"@cucumber/cucumber": "*"
Expand All @@ -103,7 +104,8 @@
"test:types": "tsd --files types/tests",
"component-tests": "mocha test/component-tests/src",
"test-cucumber": "mocha test/cucumber-integration-tests --parallel",
"coverage": "npx nyc report --reporter=text-lcov > ./coverage/mocha_coverage.lcov"
"coverage": "npx nyc report --reporter=text-lcov > ./coverage/mocha_coverage.lcov",
"prepare": "husky install"
},
"eslintConfig": {
"extends": "eslint:recommended",
Expand Down

0 comments on commit 9f3c016

Please sign in to comment.