Last active
July 9, 2019 09:52
-
-
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.
This file contains hidden or 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
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