Created
November 23, 2018 16:37
-
-
Save miladvafaeifard/21c3013e5be9ac37300e3a177c0edaf8 to your computer and use it in GitHub Desktop.
typescript validation and testing (tslint)
This file contains hidden or 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 | |
# | |
# An example hook script to verify what is about to be committed. | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status after issuing an appropriate message if | |
# it wants to stop the commit. | |
# | |
# To enable this hook, rename this file to "pre-commit". | |
#!/bin/sh | |
function print(){ | |
echo -e $1 | |
} | |
function logFailed() { | |
print "\033[41mCOMMIT FAILED for $1:\033[0m Your commit contains files that should pass $1 but do not. Please fix the $1 errors and try again.\n" | |
} | |
passLint=true | |
passTest=true | |
print "\nValidating TypeScript:\n" | |
cd RVM/rvm-external-client | |
ng lint | |
if [ $? -eq 0 ] ; then | |
print "\t\033[32mtslint Passed\033[0m" | |
else | |
print "\t\033[31mtslint Failed\033[0m" | |
passLint=false | |
fi | |
print "\nTypeScript validation complete\n" | |
if $passLint ; then | |
print "\nStarting tests\n" | |
ng test --single-run | |
if [ $? -eq 0 ] ; then | |
print "\t\033[32mTest Passed\033[0m" | |
else | |
print "\t\033[31mTest Failed\033[0m" | |
passTest=false | |
fi | |
print "\nFinished tests\n" | |
fi | |
if $passLint && $passTest ; then | |
print "\033[42mCOMMIT SUCCEEDED\033[0m\n" | |
else | |
if ! $passLint ; then | |
logFailed "tslint" | |
else | |
logFailed "test" | |
fi | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment