Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Last active November 28, 2021 12:33
Show Gist options
  • Save Fraasi/9740ab7500e24caf06cb177ec5c89641 to your computer and use it in GitHub Desktop.
Save Fraasi/9740ab7500e24caf06cb177ec5c89641 to your computer and use it in GitHub Desktop.
small bash script to print out command to update all (dev)dependencies from package.json to @latest
#!/bin/bash
USAGE="Usage:
npm-update-all
-> prints all dependencies
-d
-> prints all devDependencies
from current dirs package.json
in a ready list to copy paste
& update all dependencies to @latest"
echo ''
if ! command -v jq &>/dev/null; then
echo "jq must be installed and in PATH to run this script"
echo "https://stedolan.github.io/jq/download/"
exit 1
fi
if [[ ! -f ./package.json ]]; then
echo "no package.json found in current directory"
echo "$USAGE"
exit 1
fi
if [[ -z $1 ]]; then
echo "npm install $(jq -j '.dependencies | keys | join("@latest ")' package.json)@latest"
fi
case $1 in
-d)
echo "npm install -D $(jq -j '.devDependencies | keys | join("@latest ")' package.json)@latest"
;;
*)
echo "$USAGE"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment