Skip to content

Instantly share code, notes, and snippets.

@DoodlingDev
Last active February 16, 2018 05:33
Show Gist options
  • Save DoodlingDev/dcf5738da2348a0644055d90bbd4133b to your computer and use it in GitHub Desktop.
Save DoodlingDev/dcf5738da2348a0644055d90bbd4133b to your computer and use it in GitHub Desktop.
Javascript pre-push commit hook
#!/bin/sh
check_exit_code () {
if [[ "${1}" -ne "0" ]]; then printf "{$2}"; exit 1; fi
}
RED=$(tput setaf 1)
WHITE=$(tput setaf 7)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
printf "\n-------------- $GREEN"
printf "\n running prettier $NORMAL"
printf "\n--------------\n"
yarn prettier --trailing-comma all --write -l src/**/**/*.js
check_exit_code $? "$RED Prettier wrote to the files listed above. Push aborted. Review and commit changes to continue $NORMAL\n"
printf "$GREEN success!\n $NORMAL"
printf "\n-------------- $GREEN"
printf "\n running flow $NORMAL"
printf "\n--------------\n"
yarn flow
check_exit_code $? "$RED Flow errors, commit aborted $NORMAL\n"
printf "$GREEN success!\n $NORMAL"
printf "\n------------------------- $GREEN"
printf "\n running jest test suite $NORMAL"
printf "\n-------------------------\n"
yarn test
check_exit_code $? "$RED Test failures, commit aborted $NORMAL"
printf "$GREEN success!\n $NORMAL"
printf "\n----------------$GREEN"
printf "\n running eslint$NORMAL"
printf "\n----------------\n"
yarn lint
check_exit_code $? "$RED ESlint errors, commit aborted$NORMAL"
printf "$GREEN success!\n $NORMAL"
printf "\n----------------------------------- $GREEN"
printf "\n running cypress integration tests $NORMAL"
printf "\n-----------------------------------\n"
yarn run cypress:headless
check_exit_code $? "$RED Test failures, commit aborted $NORMAL\n"
printf "$GREEN success!\n$NORMAL"
printf "$GREEN Success!\nContinuing commit! $NORMAL"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment