Path: blob/main/Tools/scripts/npmjs-get-latest-version.sh
17720 views
#!/bin/sh1#2# MAINTAINER: [email protected]34set -e5set -o pipefail67export LC_ALL=C89##10## npmjs-get-latest-version.sh: retrieves the latest version of a given Node.js package as registered on https://registry.npmjs.org11##1213# args1415PACKAGE_NAME="$1"1617if [ -z "$PACKAGE_NAME" ]; then18echo "Usage: $0 <package-name>"19echo "Example: $0 @github/copilot"20echo "Example: $0 express"21exit 122fi2324# check that packaged dependencies are installed2526for dep in curl jq; do27if ! which $dep >/dev/null 2>&1; then28echo "error: the '$dep' dependency is missing"29if [ $dep = "curl" ]; then30echo "... please install the 'curl' package"31elif [ $dep = "jq" ]; then32echo "... please install the 'jq' package"33fi34exit 135fi36done373839# MAIN4041curl -H "Accept: application/json" https://registry.npmjs.org/$PACKAGE_NAME/latest 2>/dev/null |42grep -v "Not Found" |43jq -r '.version' ||44! echo "failed to find the Node.js package '$PACKAGE_NAME'"454647