Skip to content

Instantly share code, notes, and snippets.

@Powell-v2
Last active July 9, 2019 09:52
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 Powell-v2/ebdbbc48ec1c9f80b26b335c5907d423 to your computer and use it in GitHub Desktop.
Save Powell-v2/ebdbbc48ec1c9f80b26b335c5907d423 to your computer and use it in GitHub Desktop.
Updates all minor updates and patches. Useful if all versions in a project are exact.
PACKAGES_TO_UPDATE=()
function get_major_version { echo $(echo $1 | grep -o -E '^[0-9]{1,2}'); }
# https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
{
while read package current wanted latest location
do
# Filter out major updates.
if [ "$(get_major_version $current)" = "$(get_major_version $latest)" ]; then
PACKAGES_TO_UPDATE+=("${package}@latest")
fi
done
} < <(npm outdated | awk 'NR>1')
npm install "${PACKAGES_TO_UPDATE[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment