Created
November 11, 2020 09:00
-
-
Save LissetteIbnz/af6ddf2fb8729ff7a1a89bbc4cb7f7ec to your computer and use it in GitHub Desktop.
Scripts para comprobar cambios de dependencias npm y ejecutar tareas en base a ello
This file contains 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 | |
# Looks for changes to package.json and automates running tasks. | |
# An adaptation of https://gist.github.com/stefansundin/82051ad2c8565999b914 | |
echo "Check installed dependencies and execute npm install and pod install" | |
# post-checkout hook - looks for changes to package.json, | |
# when you change branches, and if found, reinstalls the given packages every | |
# Exit early if this was only a file checkout, not a branch change ($3 == 1) | |
[[ $3 == 0 ]] && exit 0 | |
oldRef=$1 | |
newRef=$2 | |
# Exit early if the local branch is behind the remote | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u} 2> /dev/null) | |
BASE=$(git merge-base @ @{u} 2> /dev/null) | |
if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then | |
echo "You are behind origin, not running bundle/migrate post-checkout hook." | |
exit 1 | |
fi | |
function changed { | |
git diff --name-only $oldRef $newRef | grep "^$1" > /dev/null 2>&1 | |
} | |
if changed 'package.json'; then | |
echo "Package.json changed, installing" | |
npm install && cd ios && pod install | |
fi |
This file contains 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 | |
# Looks for changes to package.json and automates running tasks. | |
# An adaptation of https://gist.github.com/stefansundin/82051ad2c8565999b914 | |
echo "Check installed dependencies and execute npm install and pod install" | |
function changed { | |
git diff --name-only HEAD@{2} HEAD | grep "^$1" > /dev/null 2>&1 | |
} | |
if changed 'package.json'; then | |
echo "Package.json changed, installing" | |
npm install && cd ios && pod install | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Puedes usarlo en conjunto con la librería husky o crear un git hook de forma manual: