Skip to content

Instantly share code, notes, and snippets.

@earnubs
Created June 25, 2021 11:56
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 earnubs/b4ddcbbd2493edbee4d96354145c575a to your computer and use it in GitHub Desktop.
Save earnubs/b4ddcbbd2493edbee4d96354145c575a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
###
# Creates a stacked set of upgrade branches from outdated npm modules
# - use on major version upgrades (use `npm update` for minor)
###
set -e
git_stuff() {
if [[$3 =~ alpha|beta ]]; then
return 0
fi
BRANCH="upgrade_$1_from_$2_to_$3"
echo $BRANCH
git checkout -b $BRANCH
npm i $1@$3
git commit -am "Upgrade $1 from $2 to $3" --no-verify
git push --no-verify
}
export -f git_stuff
npm outdated --json | \
jq -Mrc 'with_entries(.value = ({name: .key} + .value)) | .[] | "\(.name) \(.current) \(.latest)"' | \
xargs -ptl bash -c 'git_stuff $0 $1 $2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment