Created
March 23, 2025 12:50
-
-
Save aozisik/d54acfb3ec5047866bb46f87a51dc2ef to your computer and use it in GitHub Desktop.
Remove reproducible folders from your code directory (node_modules, vendor, Pods). Useful for backups.
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 | |
# Colors for better readability | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
NC='\033[0m' # No Color | |
# Set starting directory - default is current directory | |
START_DIR="${1:-.}" | |
# Counters for summary | |
NODE_MODULES_REMOVED=0 | |
VENDOR_REMOVED=0 | |
PODS_REMOVED=0 | |
echo -e "${GREEN}Starting cleanup in: ${START_DIR}${NC}" | |
echo -e "${YELLOW}This script will remove:${NC}" | |
echo -e "${YELLOW}1. node_modules folders where package.json exists${NC}" | |
echo -e "${YELLOW}2. vendor folders where composer.json exists${NC}" | |
echo -e "${YELLOW}3. Pods folders where Podfile exists${NC}" | |
echo | |
# Function to process a directory | |
process_directory() { | |
local dir="$1" | |
# Skip node_modules and vendor directories in our search | |
if [[ "$dir" == *"/node_modules"* || "$dir" == *"/vendor"* || "$dir" == *"/Pods"* ]]; then | |
return | |
fi | |
# Check if current directory has package.json and node_modules | |
if [ -f "$dir/package.json" ] && [ -d "$dir/node_modules" ]; then | |
echo -e "${YELLOW}Removing node_modules in ${dir}${NC}" | |
rm -rf "${dir}/node_modules" | |
NODE_MODULES_REMOVED=$((NODE_MODULES_REMOVED + 1)) | |
fi | |
# Check if current directory has composer.json and vendor | |
if [ -f "$dir/composer.json" ] && [ -d "$dir/vendor" ]; then | |
echo -e "${YELLOW}Removing vendor in ${dir}${NC}" | |
rm -rf "${dir}/vendor" | |
VENDOR_REMOVED=$((VENDOR_REMOVED + 1)) | |
fi | |
# Check if current directory has Podfile and Pods | |
if [ -f "$dir/Podfile" ] && [ -d "$dir/Pods" ]; then | |
echo -e "${YELLOW}Removing vendor in ${dir}${NC}" | |
rm -rf "${dir}/Pods" | |
PODS_REMOVED=$((PODS_REMOVED + 1)) | |
fi | |
# Process subdirectories | |
for subdir in "$dir"/*; do | |
if [ -d "$subdir" ]; then | |
process_directory "$subdir" | |
fi | |
done | |
} | |
# Start processing from the root directory | |
process_directory "$START_DIR" | |
# Print summary | |
echo | |
echo -e "${GREEN}=== Cleanup Summary ===${NC}" | |
echo -e "${YELLOW}node_modules directories removed: ${NODE_MODULES_REMOVED}${NC}" | |
echo -e "${YELLOW}vendor directories removed: ${VENDOR_REMOVED}${NC}" | |
echo -e "${YELLOW}Pods directories removed: ${PODS_REMOVED}${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this, simply run: