Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pre-push hook with GitHub Desktop by detecting windows #515

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@

set -eu

NPM_CMD="npm"

if ! (type $NPM_CMD >> /dev/null); then
echo "npm not found, trying to make it available using nvm..."
if type nvm >> /dev/null; then
echo "nvm found, using it to install the latest lts node"
nvm use --lts
else
echo "nvm not found, trying to make it available using the nvm.sh"
# try to make it available based on https://github.com/typicode/husky/issues/912#issuecomment-817522060
export NVM_DIR="$HOME/.nvm/nvm.sh"
. "$(dirname $NVM_DIR)/nvm.sh"

export NVM_DIR="$HOME/.nvm"
a=$(nvm ls --no-colors | grep 'node')
v=$(echo "$a" | sed -E 's/.*\(-> ([^ ]+).*/\1/')

export PATH="$NVM_DIR/versions/node/$v/bin:$PATH"

if ! (type $NPM_CMD >> /dev/null); then
echo "no variant of npm or nvm found, trying to use the npm.cmd"
NPM_CMD="npm.cmd"

find_npm_linux() {
export NPM_CMD="npm"

if ! (type $NPM_CMD >> /dev/null); then
echo "npm not found, trying to make it available using nvm..."
if type nvm >> /dev/null; then
echo "nvm found, using it to install the latest lts node"
nvm use --lts
else
echo "nvm not found, trying to make it available using the nvm.sh"
# try to make it available based on https://github.com/typicode/husky/issues/912#issuecomment-817522060
export NVM_DIR="$HOME/.nvm/nvm.sh"
. "$(dirname $NVM_DIR)/nvm.sh"

export NVM_DIR="$HOME/.nvm"
a=$(nvm ls --no-colors | grep 'node')
v=$(echo "$a" | sed -E 's/.*\(-> ([^ ]+).*/\1/')

export PATH="$NVM_DIR/versions/node/$v/bin:$PATH"

if ! (type $NPM_CMD >> /dev/null); then
echo "no variant of npm or nvm found, trying to use the npm.cmd"
export NPM_CMD="npm.cmd"
fi
fi
fi
}

if [ -z "${OSTYPE+x}" ]; then
find_npm_linux
else
case "$OSTYPE" in
msys*) export NPM_CMD="npm.cmd";;
*) find_npm_linux ;;
esac
fi


Expand Down