Created
May 4, 2020 02:04
-
-
Save rexxars/b840dc2c03d0efb01696562f5c5310ac to your computer and use it in GitHub Desktop.
Use yarn instead of npm if there is a `yarn.lock`
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
npm() { | |
if [[ ($1 == "i" || $1 == "install") && -e yarn.lock ]]; then | |
read "REPLY?Use yarn (Y/n)? " | |
echo "" | |
if [[ $REPLY =~ ^[Yy]$ || $REPLY == "" ]]; then | |
if [[ $2 == "--save-dev" ]]; then | |
echo "yarn add --dev ${@:3}" | |
command yarn add --dev "${@:3}" | |
return $? | |
elif [[ $2 == "--save" ]]; then | |
echo "yarn add ${@:3}" | |
command yarn add "${@:3}" | |
return $? | |
elif [[ $2 != "" ]]; then | |
echo "yarn add ${@:2}" | |
command yarn add "${@:2}" | |
return $? | |
else | |
command yarn | |
return $? | |
fi | |
fi | |
fi | |
command npm "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment