Created
August 21, 2023 06:33
-
-
Save herisulistiyanto/63dbc5e3a06acefeea29dd204450aeb0 to your computer and use it in GitHub Desktop.
node-modules-cleaner.sh
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
#!/usr/bin/env bash | |
clear | |
ROOT_PATH="put/your/parent/folder/path/here" | |
# Function to prompt and remove | |
function prompt_and_remove() { | |
local folder_path="$1" | |
local folder_size=$(du -sh "$folder_path" | cut -f1) | |
echo "Size of node_modules: $folder_size" | |
echo "Path: $folder_path" | |
read -p "Do you want to remove this node_modules folder? (Y/y or N/n): " confirmation | |
if [ "$confirmation" == "Y" ] || [ "$confirmation" == "y" ]; then | |
rm -rf "$folder_path" | |
echo "node_modules folder has been cleared at $folder_path." | |
else | |
echo "node_modules folder was not cleared at $folder_path." | |
fi | |
} | |
# Capture the find output into a variable | |
folders=$(find "$ROOT_PATH" -name "node_modules" -type d -prune) | |
# Iterate over the folders and prompt for each | |
IFS=$'\n' | |
for folder_path in $folders; do | |
prompt_and_remove "$folder_path" | |
done | |
echo "Process completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment