Last active
December 5, 2018 09:21
-
-
Save hjzheng/8b8a37f6f98473ca64069823139436f0 to your computer and use it in GitHub Desktop.
auto-switch-node-version.sh
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
#!/bin/bash | |
# usage: auto-switch-node-version.sh v8.11.1 'npm install&&npm run build:qa' | |
# you can also use nvm run 8.11.1 app.js or nvm exec 8.11.1 node app.js | |
newNodeVersion=$1 | |
oldNodeVersion=`node -v` | |
source ~/.nvm/nvm.sh | |
if nvm use --silent ${newNodeVersion}; then | |
echo "switch node ${newNodeVersion} success!!!" | |
else | |
nvm install ${newNodeVersion} | |
fi | |
if eval $2; then | |
nvm use --silent ${oldNodeVersion} | |
else | |
nvm use --silent ${oldNodeVersion} | |
exit 1 | |
fi | |
echo "switch node ${oldNodeVersion} back!!!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment