|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Remove the globally installed @patternfly/patternfly-cli package from npm. |
| 3 | +# Does not remove Node.js, nvm, Corepack, or GitHub CLI. |
| 4 | + |
| 5 | +# Set script to stop on most failures. |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +error() { |
| 9 | + printf '\n[%s] ERROR: %s\n\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" "$*" >&2 |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +info() { |
| 14 | + printf '[uninstall] %s\n' "$*" |
| 15 | +} |
| 16 | + |
| 17 | +warn() { |
| 18 | + printf '[uninstall] WARNING: %s\n' "$*" >&2 |
| 19 | +} |
| 20 | + |
| 21 | +require_cmd() { |
| 22 | + command -v "$1" >/dev/null 2>&1 |
| 23 | +} |
| 24 | + |
| 25 | +ensure_nvm_loaded() { |
| 26 | + export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" |
| 27 | + if [ -s "$NVM_DIR/nvm.sh" ]; then |
| 28 | + # shellcheck source=/dev/null |
| 29 | + . "$NVM_DIR/nvm.sh" |
| 30 | + return 0 |
| 31 | + fi |
| 32 | + return 1 |
| 33 | +} |
| 34 | + |
| 35 | +ensure_node_for_npm() { |
| 36 | + if require_cmd node && require_cmd npm; then |
| 37 | + return 0 |
| 38 | + fi |
| 39 | + if ensure_nvm_loaded; then |
| 40 | + nvm use default >/dev/null 2>&1 || true |
| 41 | + fi |
| 42 | + if require_cmd node && require_cmd npm; then |
| 43 | + return 0 |
| 44 | + fi |
| 45 | + error "Node.js and npm are required to uninstall the package. Install Node or load nvm (see install script), then try again." |
| 46 | +} |
| 47 | + |
| 48 | +uninstall_patternfly_cli() { |
| 49 | + info "Removing @patternfly/patternfly-cli from global npm packages." |
| 50 | + npm uninstall -g @patternfly/patternfly-cli || error "npm failed to uninstall @patternfly/patternfly-cli. Check permissions and which Node/npm you are using ($(command -v npm 2>/dev/null || echo 'npm not found'))." |
| 51 | +} |
| 52 | + |
| 53 | +main() { |
| 54 | + info "Uninstalling PatternFly CLI (global npm package only)." |
| 55 | + ensure_node_for_npm |
| 56 | + uninstall_patternfly_cli |
| 57 | + |
| 58 | + if require_cmd patternfly-cli; then |
| 59 | + warn "patternfly-cli is still on PATH at $(command -v patternfly-cli). You may have another global install under a different Node version or runtime." |
| 60 | + fi |
| 61 | + |
| 62 | + printf '\n' |
| 63 | + printf 'SUCCESS: @patternfly/patternfly-cli has been removed from this npm global prefix.\n' |
| 64 | + printf '\n' |
| 65 | +} |
| 66 | + |
| 67 | +main "$@" |
0 commit comments