Skip to content

Instantly share code, notes, and snippets.

@krystofbe
Last active March 5, 2019 17:45
Show Gist options
  • Save krystofbe/7737fb5f5c4edc6e14341ed773769d7c to your computer and use it in GitHub Desktop.
Save krystofbe/7737fb5f5c4edc6e14341ed773769d7c to your computer and use it in GitHub Desktop.
Elixir, Phoenix, TypeScript, tslint pre-commit hook
#!/bin/sh
printf "\nValidating Elixir:\n"
# credo checks before commit
mix credo
CREDO_RES=$?
if [ $CREDO_RES -ne 0 ]; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass credo but do not. Please fix the credo errors and try again.\n"
exit $CREDO_RES
fi
# tests
mix coveralls
TEST_RES=$?
if [ $TEST_RES -ne 0 ]; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass $(mix test) but do not. Please fix the elixir errors and try again.\n"
exit $TEST_RES
fi
cd assets
PASS=true
printf "\nValidating TypeScript with tslint:\n"
./node_modules/.bin/tslint --config tslint.json --project .
if [[ "$?" == 0 ]]; then
printf "\t\033[32mTSLint Passed: $FILE\033[0m"
else
printf "\t\033[41mTSLint Failed: $FILE\033[0m"
PASS=false
fi
printf "\nTypeScript tslint validation completed!\n"
if ! $PASS; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass TSLint but do not. Please fix the TSLint errors and try again.\n"
exit 1
fi
PASS=true
printf "\nValidating TypeScript with TypeScript compiler:\n"
./node_modules/typescript/bin/tsc -p tsconfig.json --noEmit
if [[ "$?" == 0 ]]; then
printf "\t\033[32mtsc Passed: $FILE\033[0m"
else
printf "\t\033[41mtsc Failed: $FILE\033[0m"
PASS=false
fi
printf "\nTypeScript compiler validation completed!\n"
if ! $PASS; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass tsc but do not. Please fix the tsc errors and try again.\n"
exit 1
else
printf "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment