Skip to content

Instantly share code, notes, and snippets.

@eschaefer
Last active July 19, 2016 20:55
Show Gist options
  • Save eschaefer/737fe311d77fdc82ba35d764a91ab927 to your computer and use it in GitHub Desktop.
Save eschaefer/737fe311d77fdc82ba35d764a91ab927 to your computer and use it in GitHub Desktop.
Swap node_modules folders when they're different between git branches
#!/bin/bash
# Assumes you are not committing node_modules to git. You really shouldn't...
#
# 1. Save bash script in some folder like $HOME/Scripts/
# 2. Add nswap alias to your .bash_profile:
# alias nswap="bash $HOME/Scripts/node-modules-swap.sh"
e=$(ls | grep node_modules)
if [ $e == "node_modules" ]; then
echo "Swapping node_modules..."
mkdir ~/Scripts/nodeswap/old/
cp -rf node_modules ~/Scripts/nodeswap/old
rm -rf node_modules
cp -rf ~/Scripts/nodeswap/new/node_modules ./
rm -rf ~/Scripts/nodeswap/new
mv ~/Scripts/nodeswap/old ~/Scripts/nodeswap/new
else
echo "No node_modules folder found. Are you in the right directory?"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment