Skip to content

Instantly share code, notes, and snippets.

@hansogj
Forked from lebbe/npmu
Last active July 24, 2024 07:53
Show Gist options
  • Save hansogj/66f8acbbc85a212ff3725b0b3e944e87 to your computer and use it in GitHub Desktop.
Save hansogj/66f8acbbc85a212ff3725b0b3e944e87 to your computer and use it in GitHub Desktop.
Automatically perform npm updates and make it a pull request
#!/bin/bash -x
# Update all minor and patch versions of your own dependencies, and thereafter
# update all transitive dependencies. Use the JIRA-number as first and only argument.
# Put this, for instance, in /usr/bin and make it executable:
#
# sudo mv npmu /usr/bin/npmu
# sudo chmod 744 /usr/bin/npmu
function npm-clean-force-install() {
set -x
rm -rf node_modules
npm cache clear --force
npm install --progress $@
set +x
if [ -x "$(command -v notify-send)" ]; then
notify-send "npm done" "npm forced install '$*'"
fi
}
function npm-update-dependencies() {
SAFEIFS=$IFS
IFS=$(echo -en "\n\b")
if [ $# -lt 1 ]; then
echo "$0: not enough arguments, try:"
echo "$0 [JIRA-#]"
IFS=$SAFEIFS
return 2
elif [ $# -gt 1 ]; then
echo "$0: too many arguments, try:"
echo "$0 [JIRA-#]"
IFS=$SAFEIFS
return 2
fi
if [ $(git branch --list master) ]; then
git checkout master
else
git checkout main
fi
set -x
git pull
git checkout -b "feature/$1-update-deps"
npm i -g npm-check-updates
ncu -t minor -u
npm-clean-force-install
git add .
git commit -m "feat(npm) [$1]: Update minor and patch version of all deps, and update all transitive deps."
git push --set-upstream origin "feature/$1-update-deps"
set +x
IFS=$SAFEIFS
}
function pnpm-clean-force-install() {
set -x
find . -type d -name node_modules -exec rm -rf {} \;
pnpm prune
pnpm install $@
set +x
if [ -x "$(command -v notify-send)" ]; then
notify-send "pnpm done" "pnpm forced install '$*'"
fi
}
alias npm-u="npm-update-dependencies"
alias npm-fi="npm-clean-force-install"
if [ -x "$(command -v pnpm)" ]; then
alias pn=pnpm
alias pn-fi="pnpm-clean-force-install"
alias pnpm-fi="pnpm-clean-force-install"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment