Created
June 17, 2024 18:36
-
-
Save abarmat/026f3d6aef778413c6f4e72b290c3618 to your computer and use it in GitHub Desktop.
Recursively remove packages installations from a number of languages
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 | |
# Function to perform cleanup for Rust projects | |
cleanup_rust() { | |
if [ -f "Cargo.toml" ] && [ -d "target" ]; then | |
echo "[Rust] Cleaning project in $(pwd)" | |
cargo clean | |
fi | |
if [ -d "target" ]; then | |
echo "[Rust] Cargo clean did not work removing with rm in $(pwd)" | |
rm -rf target | |
fi | |
} | |
# Function to perform cleanup for Node.js projects | |
cleanup_node() { | |
if [ -d "node_modules" ]; then | |
echo "[Node] Removing node_modules in $(pwd)" | |
rm -rf node_modules | |
fi | |
} | |
# Function to perform cleanup for Next.js projects | |
cleanup_next() { | |
if [ -d ".next" ]; then | |
echo "[Next] Removing next in $(pwd)" | |
rm -rf .next | |
fi | |
} | |
# Function to perform cleanup for Go projects | |
cleanup_go() { | |
if [ -d "go/pkg" ]; then | |
echo "[Go] Removing Go packages in $(pwd)" | |
rm -rf go/pkg | |
fi | |
} | |
# Function to detect project type and perform cleanup | |
detect_and_cleanup() { | |
local dir=$1 | |
(cd "$dir" && cleanup_rust && cleanup_node && cleanup_next && cleanup_go) | |
} | |
# Function to scan directories recursively and perform cleanup | |
scan_and_cleanup() { | |
for dir in "$1"/*; do | |
if [ -d "$dir" ]; then | |
detect_and_cleanup "$dir" | |
scan_and_cleanup "$dir" | |
fi | |
done | |
} | |
# Check if directory is provided as an argument | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <directory>" | |
exit 1 | |
fi | |
# Starting point | |
ROOT_DIR=$1 | |
# Recursively scan and clean up projects | |
echo "Running cleanup on ${ROOT_DIR}" | |
scan_and_cleanup "$ROOT_DIR" | |
echo "Cleanup completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment