Skip to content

Instantly share code, notes, and snippets.

@evanshortiss
Last active August 29, 2015 14:24
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 evanshortiss/1f1277bb6a7d4c01ea96 to your computer and use it in GitHub Desktop.
Save evanshortiss/1f1277bb6a7d4c01ea96 to your computer and use it in GitHub Desktop.
Alias that runs a function to determine which version of Cordova to use for your environment.
# Use a local version of Cordova when possible
alias cordova=exec_cordova_local
# Determine cordova version to use
exec_cordova_local() {
# Default path Cordova should be at if installed...
cpath="/usr/local/lib/node_modules/cordova/bin/cordova"
if [ -e node_modules/.bin/cordova ]
then
# Use a locally installed version if possible
cpath="node_modules/.bin/cordova"
elif [ -e ~/.nvm ]
then
# No local version, but user has nvm installed,
# so use whichever version is installed for current node runtime
nver=`nvm ls | grep "current:" | cut -c 11-18`
cpath="~/.nvm/${nver}/lib/node_modules/cordova/bin/cordova"
fi
echo "Using Cordova version located at ${cpath}"
cpath+=' "$@"'
eval $cpath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment