Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rexxars
Created May 4, 2020 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexxars/b840dc2c03d0efb01696562f5c5310ac to your computer and use it in GitHub Desktop.
Save rexxars/b840dc2c03d0efb01696562f5c5310ac to your computer and use it in GitHub Desktop.
Use yarn instead of npm if there is a `yarn.lock`
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