Last active
March 29, 2019 08:35
-
-
Save airtoxin/babb07e25d2cdd7a8a3b0cae7a5f6764 to your computer and use it in GitHub Desktop.
cache-node_modules git hook
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 | |
echo "[cache-node_modules] START" | |
CURRENT_DIR_NAME=`basename $(pwd)` | |
BRANCH_FROM=`git reflog show -q | head -n1 | awk '$3 == "checkout:" && $4 == "moving" {print $6}'` | |
BRANCH_TO=`git reflog show -q | head -n1 | awk '$3 == "checkout:" && $4 == "moving" {print $8}'` | |
BRANCH_FROM_CACHE_NAME="/Library/Caches/${CURRENT_DIR_NAME}_${BRANCH_FROM}_node_modules" | |
BRANCH_TO_CACHE_NAME="/Library/Caches/${CURRENT_DIR_NAME}_${BRANCH_TO}_node_modules" | |
if [ -d "node_modules" ]; then | |
echo "[cache-node_modules] Cache node_modules to ${BRANCH_FROM_CACHE_NAME}" | |
mv node_modules ${BRANCH_FROM_CACHE_NAME} | |
fi | |
if [ -d "${BRANCH_TO_CACHE_NAME}" ]; then | |
echo "[cache-node_modules] Restore node_modules from cache." | |
mv ${BRANCH_TO_CACHE_NAME} node_modules | |
fi | |
echo "[cache-node_modules] Refresh node_modules" | |
yarn | |
echo "[cache-node_modules] DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment