Last active
March 28, 2020 18:23
-
-
Save chadlavi/6b74e9ccbbf600c3bd1ee4f081039d95 to your computer and use it in GitHub Desktop.
a bash function to quickly identify any yarn links you've got set up currently
This file contains hidden or 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
yarnlinks() { | |
bold() { | |
echo -e "\033[1m$1\033[0m" | |
} | |
italic() { | |
echo -e "\033[3m$1\033[0m" | |
} | |
italic "looking for links in ~/.config/yarn/link ..." | |
LINKS=$(find ~/.config/yarn/link -type l -ls | awk '{print $11 "," $13}') | |
if [ -z "$LINKS" ]; then | |
echo " > no links found in in ~/.config/yarn/link" | |
else | |
echo "$LINKS" | while read -r LINK; do | |
PKG=$(echo "$LINK" | awk -F ',' '{print $1}' | awk -F 'link/' '{print $2}') | |
FROM=$(echo "$LINK" | awk -F ',' '{print $2}' | awk -F '/node_modules' '{print $1}' | awk -F '/' '{print $NF}') | |
bold " > \"$PKG\" is linked from within \"$FROM\"" | |
done | |
if [ "$1" = "rm" ]; then | |
rm -rf ~/.config/yarn/link/* && bold " > deleted yarn links" | |
fi | |
fi | |
if [ -d "$(pwd)/node_modules" ]; then | |
italic "looking for links in ${PWD##*/}/node_modules ..." | |
MODULES=$(find node_modules node_modules/\@* -depth 1 -type l -print | awk -F 'node_modules/' '{print $2}') | |
if [ -z "$MODULES" ]; then | |
echo " > no modules linked in in ${PWD##*/}/node_modules" | |
else | |
echo "$MODULES" | while read -r MODULE ; do | |
bold "> Linked module used in this app: \"$MODULE\"" | |
done | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment