Skip to content

Instantly share code, notes, and snippets.

@x86demon
Last active January 30, 2024 09:47
Show Gist options
  • Save x86demon/c768f1890cb90a52325e707f78ddfb0b to your computer and use it in GitHub Desktop.
Save x86demon/c768f1890cb90a52325e707f78ddfb0b to your computer and use it in GitHub Desktop.
#!/bin/sh
SCRIPT=`basename "$0"`
MASTER_NPM_PATH="/opt/node/v20/bin"
NPM_PATH_51="/opt/node/v18/bin"
NPM_PATH_50="/opt/node/v16/bin"
OLD_NPM_PATH="/opt/node/v14/bin"
SCRIPT_BIN="${OLD_NPM_PATH}/${SCRIPT}"
if [[ -f .nvmrc ]]
then
NODE_VERSION=$(<.nvmrc)
SCRIPT_BIN="/opt/node/v${NODE_VERSION}/bin/${SCRIPT}"
else
CURRENT_GIT_BRANCH=$(git branch --remote --verbose --no-abbrev --contains | sed -rne 's/^[^\/]*\/([^\ ]+).*$/\1/p' 2> /dev/null)
if [[ $CURRENT_GIT_BRANCH == "" ]]
then
CURRENT_GIT_BRANCH=$(git branch --show-current 2> /dev/null)
fi
if [[ $CURRENT_GIT_BRANCH =~ "master" || !($CURRENT_GIT_BRANCH =~ "5.1" || $CURRENT_GIT_BRANCH =~ "_51" || $CURRENT_GIT_BRANCH =~ "5.0" || $CURRENT_GIT_BRANCH =~ "_50" || $CURRENT_GIT_BRANCH =~ "4.2" || $CURRENT_GIT_BRANCH =~ "_42" || $CURRENT_GIT_BRANCH =~ "4.1" || $CURRENT_GIT_BRANCH =~ "_41" || $CURRENT_GIT_BRANCH =~ "3.1" || $CURRENT_GIT_BRANCH =~ "_31" || $CURRENT_GIT_BRANCH =~ "2.6")]]
then
SCRIPT_BIN="${MASTER_NPM_PATH}/${SCRIPT}"
fi
if [[ $CURRENT_GIT_BRANCH =~ "5.1" || $CURRENT_GIT_BRANCH =~ "_51" ]]
then
SCRIPT_BIN="${NPM_PATH_51}/${SCRIPT}"
fi
if [[ $CURRENT_GIT_BRANCH =~ "5.0" || $CURRENT_GIT_BRANCH =~ "_50" ]]
then
SCRIPT_BIN="${NPM_PATH_50}/${SCRIPT}"
fi
fi
${SCRIPT_BIN} $@
@x86demon
Copy link
Author

cd /usr/local/bin
ln -s node_wrapper node
ln -s node_wrapper npm
ln -s node_wrapper npx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment