Skip to content

Instantly share code, notes, and snippets.

@tamlyn
Last active December 7, 2016 11:02
Show Gist options
  • Save tamlyn/07c25782120986bd46a8486b09642f8a to your computer and use it in GitHub Desktop.
Save tamlyn/07c25782120986bd46a8486b09642f8a to your computer and use it in GitHub Desktop.
Update and build all npm linked modules
pull-modules () {
BASE_DIR=$(pwd)
# find symlinks in node_modules
for MODULE in $(find node_modules -type l -depth 1)
do
cd "$MODULE"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Updating $MODULE ($BRANCH)..."
# Warn if index is not clean
git diff-index --quiet HEAD
GIT_STATUS=$?
if [ $GIT_STATUS != 0 ]; then
echo Warning: you have uncommitted changes in $MODULE
fi
# update code
OLD_COMMIT=$(git rev-parse HEAD)
git pull -q
NEW_COMMIT=$(git rev-parse HEAD)
# only run install if we pulled an update
if [ $OLD_COMMIT != $NEW_COMMIT ]
then
echo Updated to $NEW_COMMIT.
npm prune
# assumes that build is run automatically after install
npm install
fi
# return to project directory
cd $BASE_DIR
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment