echo "Removing bloat in node_modules..."

set -e

DIR="$(pwd)/src/node_modules"

cd $DIR
rm -rf {@babel,@pdf-lib,@types,core-js,core-js-pure,css-line-break,dompurify,fflate,pako,raf,regnerator-runtime,rgbcolor,stackblur-canvas,svg-pathdata,tslib,type-fest}

cd @fortawesome/fontawesome-free
rm -rf {css,less,metadata,scss,sprites,svgs,webfonts}
find js -type f -not -name 'all.min.js' -delete
find . -type f -name '*.tgz' -delete # for some reason it's packaging an 18MB tarball sometimes
cd $DIR

cd jquery
rm -rf src
rm -rf external
find dist -type f -not -name 'jquery.min.js' -delete
cd $DIR

cd signature_pad
rm -rf {docs,src}
rm -rf dist/types
find dist -type f -not -name 'signature_pad.umd.min.js' -delete
cd $DIR

cd pdfjs-dist
rm -rf {cmaps,image_decoders,legacy,lib,types,web}
cd $DIR

cd jspdf
rm -rf {types}
find dist -type f -not -name 'jspdf.umd.min.js' -delete
cd $DIR

cd bootstrap
rm -rf {js,scss}
cd dist
find css -type f -not -name 'bootstrap.min.css' -delete
find js -type f -not -name 'bootstrap.bundle.min.js' -delete
cd $DIR

cd html2canvas
rm -rf dist/types
cd $DIR

# Make npm stop complaining that these don't exist by actually removing them
rm -rf .bin/*
cd $DIR


echo "Cleanup finished"
