.husky/pre-push
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Get current unstaged files
unstagedFiles=`git diff --name-only --diff-filter=ACM | grep -E '\.(ts|tsx)$' | sed 's| |\\ |g'`
unstagedCount=`echo "$unstagedFiles" | wc -l | sed 's/ //g'`
echo "Current modified files ($unstagedCount):"
echo "$unstagedFiles"
# Compile the project
echo "๐จ compiling..."
yarn tsc:noemit
# Run lintier
echo "๐งน runnning linter..."
yarn lint-autofix
# Run prettifier
echo "๐งผ runnning prettier..."
yarn prettify
# If we have any modified files don't push
if [ -n "$(git status --porcelain)" ]; then
# Collect all modified files
updatedUnstagedFiles=`git diff --name-only --diff-filter=ACM | grep -E '\.(ts|tsx)$' | sed 's| |\\ |g'`
updatedStagedCount=`echo "$updatedUnstagedFiles" | wc -l | sed 's/ //g'`
echo "Modified files after linting and prettifying ($updatedStagedCount):"
echo "$updatedUnstagedFiles"
# Did linter and prettier found some issues?
newStageFilesCount=$((updatedStagedCount-unstagedCount))
if [ "$newStageFilesCount" -gt 0 ]; then
echo "โ Some files were not well formed: $newStageFilesCount"
exit 1
else
echo "โ
All files are clean!"
fi
fi
echo "๐ pushing..."
echo "โจ Done."