Skip to content

Instantly share code, notes, and snippets.

@EvanLovely
Last active June 12, 2017 19:37
Show Gist options
  • Save EvanLovely/7b9cc7e07bbade1cb51136c8d1fee9eb to your computer and use it in GitHub Desktop.
Save EvanLovely/7b9cc7e07bbade1cb51136c8d1fee9eb to your computer and use it in GitHub Desktop.
Delete dep folders: `node_modules`, `bower_components`

Delete all Dependency Folders

Removes folders like node_modules & bower_components.

Install by placing that in a .bash_profile or similar.

This would run it in current directory and recurse on down:

delete-all-dep-folders

This would run it on the folder you point to:

delete-all-dep-folders path/to/folder/
# Delete dep folders: `node_modules`, `bower_components`
# @param $1 [.] Which folder to recursively look in; defaults to cwd (`.`).
delete-all-dep-folders() {
# `-prune` prevents building up lists of `node_modules` inside `node_modules`
find ${1:-.} -type d -name "node_modules" -prune -exec rm -rf '{}' \; -exec echo 'Deleted {}' \;
find ${1:-.} -type d -name "bower_components" -prune -exec rm -rf '{}' \; -exec echo 'Deleted {}' \;
# This one is a little spooky as `vendor/` folders aren't exclusive to Composer.
# @todo Test if `composer.json` is next to `vendor/` before deleting.
# find ${1:-.} -type d -name "vendor" -prune -exec rm -rf '{}' \; -exec echo 'Deleted {}' \;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment