Created
September 27, 2018 23:46
-
-
Save dcurletti/89edd6a5b329fa01faf39148ffafa71a to your computer and use it in GitHub Desktop.
Bash script to typecheck project on TypeScript file changes
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/bash | |
# You can make the script more generic by changing the matching pattern | |
SRC_PATTERN=".*\.(ts|tsx)$" | |
# needed bc env vars change when run inside a git hook | |
# https://stackoverflow.com/questions/3542854/calling-git-pull-from-a-git-post-update-hook | |
# https://serverfault.com/questions/107608/git-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory | |
unset $(git rev-parse --local-env-vars) | |
if git diff --cached --name-only | grep --quiet -E "$SRC_PATTERN" | |
then | |
# This block executes only when there are staged files matching the pattern above | |
echo "type-checking typescript files" | |
yarn type-check | |
exit 0 | |
fi |
Can you provide yarn type-check
command ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I was able to use this script with lint-staged. I made one minor change tho:
$?
captures the result of the last executed command. This way lint-stage fails the pre-commit hook if it finds an error.