Last active
June 2, 2016 15:19
-
-
Save kylebradshaw/221d6e8cffd91a40eeca547ec055b8f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Kyle's Hook | |
###################################################################### | |
# JSHint: Run JS formatting before committing | |
###################################################################### | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") | |
if [ "$files" = "" ]; then | |
echo "no Files" | |
fi | |
valid=true | |
echo "\033[96m= Validating JavaScript with JSHint... \033[0m" | |
for file in ${files}; do | |
result=$(jshint ${file} --config .jshintrc) | |
if [ "$result" == "" ]; then | |
echo "\033[32m JSHint Passed for: ${file} \033[0m" | |
else | |
echo "\033[31m JSHint Failed for: ${file} \033[0m" | |
valid=false | |
fi | |
done | |
# echo '\n\n' "\033[96m===== JavaScript validation complete. =====\033[0m" | |
if ${valid}; then | |
echo "\033[42m \033[30mCOMMIT SUCCEEDED: JSHINT FTW!! \033[0m" | |
# printf '\n%s\n' "JSHint Succeeded" | |
else | |
echo "\033[41m COMMIT FAILED: JSHINT FTL.. \033[0m" | |
# printf '\n%s\n' "Commit Failed: Please fix all above JSHint errors and try again" | |
exit 1 | |
fi | |
###################################################################### | |
# Unit Tests: Run unit tests/specs before committing | |
###################################################################### | |
echo "\033[96m= Running Karma... \033[0m" | |
gulp karma 1> /dev/null | |
EXIT_CODE=$? | |
if [[ ${EXIT_CODE} -ne 0 ]]; then | |
# echo "[ERROR] code = " ${EXIT_CODE} | |
# echo "Karma Unit Tests failed." | |
# echo "Commit aborted." | |
echo "\033[41m COMMIT ABORTED: KARMA FTL.. \033[0m" | |
exit 1 | |
else | |
echo "\033[42m\033[30m COMMIT SUCCEEDED: KARMA FTW!! \033[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment