Skip to content

Instantly share code, notes, and snippets.

@LissetteIbnz
Created November 11, 2020 09:00
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 LissetteIbnz/af6ddf2fb8729ff7a1a89bbc4cb7f7ec to your computer and use it in GitHub Desktop.
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
#!/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
#!/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
@LissetteIbnz
Copy link
Author

Puedes usarlo en conjunto con la librería husky o crear un git hook de forma manual:

  "husky": {
    "hooks": {
      "post-checkout": "sh post-checkout.sh",
      "post-merge": "sh post-merge.sh"
    }
  },

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