Skip to content

Instantly share code, notes, and snippets.

@third774
Created July 11, 2024 04:45
Show Gist options
  • Save third774/73d69c44ef59a273e20fd321d200ad78 to your computer and use it in GitHub Desktop.
Save third774/73d69c44ef59a273e20fd321d200ad78 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if the RUN_TYPECHECKER_PRECOMMIT_HOOK environment variable is set to "true"
if [ "$RUN_TYPECHECKER_PRECOMMIT_HOOK" = "true" ]; then
echo "Running TypeScript type checker..."
# Run the TypeScript compiler in type-checking mode and capture the output
tsc_output=$(npx tsc --noEmit 2>&1)
tsc_exit_code=$?
# Check the exit code of the TypeScript compiler
if [ $tsc_exit_code -ne 0 ]; then
echo "TypeScript type check failed. Please fix the following errors before committing:"
echo "$tsc_output"
exit 1
else
echo "TypeScript type check passed."
fi
else
echo "Skipping TypeScript type checker (RUN_TYPECHECKER_PRECOMMIT_HOOK is not set to 'true')."
fi
# If we've made it this far, the commit can proceed
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment