A simple script to update all your shadcn/ui components in one go. No more updating components one by one!
The Script
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 | |
# update-shadcn-components.sh | |
# Script to bulk update all shadcn/ui components in a Next.js project | |
# Usage: ./update-shadcn-components.sh | |
# Set error handling | |
set -e | |
# Check if we're in a Next.js project | |
if [ ! -d "src/components/ui" ]; then | |
echo "Error: src/components/ui directory not found" | |
echo "Please run this script from your Next.js project root" | |
exit 1 | |
fi | |
# Log start of updates | |
echo "Starting shadcn/ui components update..." | |
echo "Checking components in src/components/ui/..." | |
# Initialize counter | |
updated=0 | |
failed=0 | |
# Update each component | |
for file in src/components/ui/*.tsx; do | |
# Extract component name | |
component=$(basename "$file" .tsx) | |
echo "Updating component: $component" | |
# Try to update the component | |
if npx shadcn@latest add -y -o "$component"; then | |
updated=$((updated + 1)) | |
echo "✓ Successfully updated $component" | |
else | |
failed=$((failed + 1)) | |
echo "✗ Failed to update $component" | |
fi | |
done | |
# Print summary | |
echo "Update complete!" | |
echo "Successfully updated: $updated components" | |
if [ $failed -gt 0 ]; then | |
echo "Failed to update: $failed components" | |
exit 1 | |
fi |
Quick Start
- Save as
update-shadcn-components.sh
- Make executable:
chmod +x update-shadcn-components.sh
- Run:
./update-shadcn-components.sh
What it does
- Updates all shadcn components in
src/components/ui/
- Shows progress for each update
- Tells you what succeeded and what failed
Before Running
- Commit your changes
- Be in your project root directory
That’s it! Simple and effective way to keep your shadcn components up to date.
Comments powered by Disqus.