bolt.diy/.husky/pre-commit

44 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
echo "🔍 Running pre-commit hook to check the code looks good... 🔍"
2024-12-13 10:33:29 +00:00
# Load NVM if available (useful for managing Node.js versions)
2024-12-02 21:53:22 +00:00
export NVM_DIR="$HOME/.nvm"
2024-12-13 10:33:29 +00:00
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
2024-12-02 21:53:22 +00:00
2024-12-13 10:33:29 +00:00
# Ensure `pnpm` is available
echo "Checking if pnpm is available..."
if ! command -v pnpm >/dev/null 2>&1; then
echo "❌ pnpm not found! Please ensure pnpm is installed and available in PATH."
exit 1
fi
2024-12-02 21:53:22 +00:00
2024-12-13 10:33:29 +00:00
# Run typecheck
echo "Running typecheck..."
if ! pnpm typecheck; then
2024-12-13 10:33:29 +00:00
echo "❌ Type checking failed! Please review TypeScript types."
echo "Once you're done, don't forget to add your changes to the commit! 🚀"
exit 1
fi
2024-12-13 10:33:29 +00:00
# Run lint
2024-12-02 21:53:22 +00:00
echo "Running lint..."
if ! pnpm lint; then
2024-12-13 10:33:29 +00:00
echo "❌ Linting failed! Run 'pnpm lint:fix' to fix the easy issues."
echo "Once you're done, don't forget to add your beautification to the commit! 🤩"
exit 1
fi
2024-12-13 08:22:21 +00:00
# Update commit.json with the latest commit hash
2024-12-13 10:33:29 +00:00
echo "Updating commit.json with the latest commit hash..."
2024-12-13 08:22:21 +00:00
COMMIT_HASH=$(git rev-parse HEAD)
2024-12-13 10:33:29 +00:00
if [ $? -ne 0 ]; then
echo "❌ Failed to get commit hash. Ensure you are in a git repository."
exit 1
fi
2024-12-13 08:22:21 +00:00
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
git add app/commit.json
2024-12-13 10:33:29 +00:00
echo "👍 All checks passed! Committing changes..."