Skip to content

Instantly share code, notes, and snippets.

@heyman333
Forked from dcurletti/ts-precommit.bash
Created March 19, 2020 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heyman333/bf1e78290d22bec4734a5e171be148e8 to your computer and use it in GitHub Desktop.
Save heyman333/bf1e78290d22bec4734a5e171be148e8 to your computer and use it in GitHub Desktop.
Bash script to typecheck project on TypeScript file changes
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment