-
-
Save neophob/0c8cfdd460b8332002e7ba74aa1e9ffd to your computer and use it in GitHub Desktop.
Prunes very-likely-uneeded files from node_modules directories
This file contains 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 | |
# Port of https://github.com/tj/node-prune to bash | |
# Also, | |
# - fixed "*.ts" being overzealous and killing .d.ts files | |
# - added some more file types from https://github.com/npm/npm/issues/5264#issuecomment-259800486 | |
# | |
# See also: | |
# - https://github.com/timoxley/cruft | |
# - https://yarnpkg.com/en/docs/cli/autoclean | |
# - https://github.com/ModClean/modclean | |
# | |
# Prunes common files that are unnecessarily published in npm packages | |
# when people don't configure `.npmignore` or package.json's `files` | |
# | |
# TODO/unclear: | |
# - *.map files | |
echo "Before: "$(du -hs .) | |
echo "Files: "$(find node_modules/ -type f | wc -l) | |
# Common unneeded files | |
find . -type d -name node_modules -prune -exec find {} -type f \( \ | |
-iname Makefile -or \ | |
-iname README -or \ | |
-iname README.md -or \ | |
-iname CHANGELOG -or \ | |
-iname CHANGELOG.md -or \ | |
-name .editorconfig -or \ | |
-name .gitmodules -or \ | |
-name .gitattributes -or \ | |
-name robot.html -or \ | |
-name .lint -or \ | |
-iname Gulpfile.js -or \ | |
-iname Gruntfile.js -or \ | |
-name .tern-project -or \ | |
-name .gitattributes -or \ | |
-name .editorconfig -or \ | |
-name .eslintrc -or \ | |
-name .jshintrc -or \ | |
-name .npmignore -or \ | |
-name .flowconfig -or \ | |
-name .documentup.json -or \ | |
-name .yarn-metadata.json -or \ | |
-name .travis.yml -or \ | |
-name thumbs.db -or \ | |
-name .tern-port -or \ | |
-name .ds_store -or \ | |
-name desktop.ini -or \ | |
-name npm-debug.log -or \ | |
-name .npmrc -or \ | |
-iname LICENSE.txt -or \ | |
-iname LICENSE.md -or \ | |
-iname LICENSE-MIT -or \ | |
-iname LICENSE-MIT.txt -or \ | |
-iname LICENSE.BSD -or \ | |
-iname LICENSE-BSD -or \ | |
-iname LICENSE-jsbn -or \ | |
-iname LICENSE -or \ | |
-iname AUTHORS -or \ | |
-iname CONTRIBUTORS -or \ | |
-name .yarn-integrity -or \ | |
-name builderror.log -or \ | |
-name "*.md" -or \ | |
-name "*.sln" -or \ | |
-name "*.obj" -or \ | |
-name "*.gypi" -or \ | |
-name "*.vcxproj" -or \ | |
-name "*.vcxproj.filters" -or \ | |
\( -name '*.ts' -and \! -name '*.d.ts' \) -or \ | |
-name "*.jst" -or \ | |
-name "*.coffee" \ | |
\) -print0 \; | xargs -0 rm -rf | |
# Common unneeded directories | |
find . -type d -name node_modules -prune -exec find {} -type d \( \ | |
-name __tests__ -or \ | |
-name test -or \ | |
-name tests -or \ | |
-name powered-test -or \ | |
-name docs -or \ | |
-name doc -or \ | |
-name website -or \ | |
-name images -or \ | |
-name assets -or \ | |
-name example -or \ | |
-name examples -or \ | |
-name coverage -or \ | |
-name node-gyp -or \ | |
-name node-pre-gyp -or \ | |
-name gyp -or \ | |
-name .nyc_output \ | |
\) -print0 \; | xargs -0 rm -rf | |
echo "After: "$(du -hs .) | |
echo "Files: "$(find node_modules/ -type f | wc -l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment