Created
June 16, 2021 14:11
-
-
Save x1unix/c1c138bece8ff1e84505e64a97b3d218 to your computer and use it in GitHub Desktop.
Recursive remove node_modules
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 | |
set -e | |
dir_name=$1 | |
node_dir="node_modules" | |
echo "Removing each node_modules in $dir_name..." | |
rm_node_modules() { | |
dir=$1 | |
echo ":: Inspecting '$dir'..." | |
if [ -d "$dir/$node_dir" ]; then | |
rm -rf -v "$dir/$node_dir"; | |
fi | |
for childdir in $dir/*; do | |
echo ":: Checking $childdir..." | |
if [ -d "$childdir" ]; then | |
rm_node_modules "$childdir" | |
fi | |
done | |
} | |
if [ ! -d "$dir_name" ]; then | |
echo "Error: not a dir - $dir_name" | |
exit 1 | |
fi | |
rm_node_modules $dir_name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment