Skip to content

Commit

Permalink
feat(githooks): check node version on checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Mar 5, 2018
1 parent cfab09c commit 1b838b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions scripts/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

SCRIPT_PATH="$(dirname "$0")/$(dirname "$(readlink "$0")")"

# Import utils
source ${SCRIPT_PATH}/utils/message

# strong some numbers
NPM_VERSION="$(npm -v)"
MAJOR_NPM_VERSION="$(npm -v | cut -d. -f1)"

NODE_VERSION="$(node -v)"

PACKAGE_DEV_DEPENDENCY="$(node -p -e "require('./package.json').devDependencies.node")"
PACKAGE_ENGINE_DEPENDENCY="$(node -p -e "require('./package.json').engines.node")"

VALIDATION_EXIT_CODE=$(${SCRIPT_PATH}/validate-engine-versions > /dev/null; echo $?)

# checking some stuff
if [ "$PACKAGE_DEV_DEPENDENCY" != "undefined" ] && [ "$MAJOR_NPM_VERSION" -lt 5 ]; then
warning "This branch uses node as a dependency, \
but you are running npm ${NPM_VERSION} which doesnt support that."
exit 1;
elif [ $VALIDATION_EXIT_CODE -ne 0 ]; then
warning "This branch requires node version v${PACKAGE_ENGINE_DEPENDENCY}, \
but you're running ${NODE_VERSION}."
exit 1
fi

info "Looks like your node version is fine."
2 changes: 1 addition & 1 deletion scripts/pre-install
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ source ${SCRIPT_PATH}/utils/marathon
# git hooks fail to install
${SCRIPT_PATH}/validate-engine-versions && \
install_marathon_raml "$MARATHON_VERSION" && \
install_hooks "pre-commit post-rewrite post-commit"
install_hooks "pre-commit post-rewrite post-commit post-checkout"

exit 0

0 comments on commit 1b838b2

Please sign in to comment.