Skip to content

Instantly share code, notes, and snippets.

@turnercore
Last active January 1, 2024 16:53
Show Gist options
  • Select an option

  • Save turnercore/6e90604412d7cf84e5c059c436d6f790 to your computer and use it in GitHub Desktop.

Select an option

Save turnercore/6e90604412d7cf84e5c059c436d6f790 to your computer and use it in GitHub Desktop.
Install shadcn complete
#!/bin/bash
# Create directories and files
mkdir -p ./components/ui
mkdir -p ./lib
touch ./lib/utils.ts
# Prompt to move globals.css
echo "Would you like to move globals.css to styles/globals.css? (y/n)"
read -r -p "[Y/n]: " move_response
move_response=${move_response:-n}
if [[ "$move_response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
mkdir -p ./styles
if [ -f "app/globals.css" ]; then
mv app/globals.css ./styles/globals.css
echo "Moved globals.css to ./styles/globals.css. Remember to use styles/globals.css for styles when prompted!"
else
touch ./styles/globals.css
echo "Created new globals.css in ./styles."
fi
else
echo "Keeping globals.css in its current location."
fi
# Run shadcn-ui init command (user interaction required)
echo "Init shadcn? (y/n)"
read -r -p "[Y/n]: " response
response=${response:-y}
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
echo "Running 'npx shadcn-ui@latest init'..."
echo "Please complete the interactive setup."
if [[ "$move_response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
echo "Make sure to use styles/globals.css for the styles when prompted!"
fi
npx shadcn-ui@latest init
# Confirmation message
read -p "Press enter once the interactive setup is complete..."
else
echo "Skipping shadcn-ui init..."
fi
# Install shadcn-ui components
echo "Would you like to install all shadcn components @latest? (y/n)"
read -r -p "[Y/n]: " response
response=${response:-y}
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
components=(
"accordion" "alert" "alert-dialog" "aspect-ratio" "avatar" "badge"
"button" "calendar" "card" "checkbox" "collapsible" "combobox"
"command" "context-menu" "data-table" "date-picker" "dialog" "dropdown-menu"
"form" "hover-card" "input" "label" "menubar" "navigation-menu"
"popover" "progress" "radio-group" "scroll-area" "select" "separator"
"sheet" "skeleton" "slider" "switch" "table" "tabs"
"textarea" "toast" "toggle" "toggle-group" "tooltip" "carousel" "drawer" "pagination"
"resizable" "sonner"
)
for component in "${components[@]}"; do
echo "Installing $component..."
yes | npx shadcn-ui@latest add "$component"
echo "Shad components installed successfully!"
done
else
echo "Skipping shadcn-ui component installation..."
fi
# Create index file if the user wants to
echo "Would you like to create an index file for your components? (y/n)"
read -r -p "[Y/n]: " response
response=${response:-y}
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
# Install ts-node if not already installed
if ! command -v ts-node &> /dev/null
then
echo "Installing ts-node..."
npm install ts-node
fi
# Download the TypeScript file from the Gist
echo "Downloading the setup-index.ts script..."
curl -o setup-index.mjs "https://gist.githubusercontent.com/turnercore/37b3b634e9e401bcf96414daa14b7453/raw/2a6baadffb97b8f89d03f51e665e4ca497343942/generateIndex.ts"
# Run the script with ts-node
echo "Running the setup-index.mjs script..."
npx ts-node setup-index.mjs
# Delete the setup-index.ts file after running
echo "Deleting the setup-index.ts script..."
rm setup-index.mjs
echo "Index file creation complete."
else
echo "Skipping index.ts generation..."
fi
echo "Shadcn install complete!"
@turnercore
Copy link
Author

Note that if you want to create an index file for the components, then the script relies on this typescript file and ts-node (and the reference needs to be updated if that .ts gist is updated).

However, this can safely be skipped.

https://gist.githubusercontent.com/turnercore/37b3b634e9e401bcf96414daa14b7453/raw/2a6baadffb97b8f89d03f51e665e4ca497343942/generateIndex.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment