Home / Log

Bash Alias: npm reset

npmreset() {
  echo '🔥 rm -rf node_modules'
  rm -rf node_modules
  echo '🔥 rm package-lock.json'
  rm package-lock.json

  # Initialize update flag to false
  update=false

  # Parse arguments
  while (( "$#" )); do
    case "$1" in
      -u|--update)
        update=true
        shift
        ;;
      *)
        shift
        ;;
    esac
  done

  # Checking for updates should only run with flag -u or --update
  if [ "$update" = true ]; then
    echo '🔥 checking for new packages'
    npx npm-check-updates -u
  fi

  echo '⚡️ npm i'
  npm i
}

Found the basics of this idea over on whitep4nth3r.com by Salma after looking to this tweet by @flaviocopes.

Date
11.03.2024
Tags
  • Bash
  • Linux