Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/Tools/scripts/npmjs-get-latest-version.sh
17720 views
1
#!/bin/sh
2
#
3
# MAINTAINER: [email protected]
4
5
set -e
6
set -o pipefail
7
8
export LC_ALL=C
9
10
##
11
## npmjs-get-latest-version.sh: retrieves the latest version of a given Node.js package as registered on https://registry.npmjs.org
12
##
13
14
# args
15
16
PACKAGE_NAME="$1"
17
18
if [ -z "$PACKAGE_NAME" ]; then
19
echo "Usage: $0 <package-name>"
20
echo "Example: $0 @github/copilot"
21
echo "Example: $0 express"
22
exit 1
23
fi
24
25
# check that packaged dependencies are installed
26
27
for dep in curl jq; do
28
if ! which $dep >/dev/null 2>&1; then
29
echo "error: the '$dep' dependency is missing"
30
if [ $dep = "curl" ]; then
31
echo "... please install the 'curl' package"
32
elif [ $dep = "jq" ]; then
33
echo "... please install the 'jq' package"
34
fi
35
exit 1
36
fi
37
done
38
39
40
# MAIN
41
42
curl -H "Accept: application/json" https://registry.npmjs.org/$PACKAGE_NAME/latest 2>/dev/null |
43
grep -v "Not Found" |
44
jq -r '.version' ||
45
! echo "failed to find the Node.js package '$PACKAGE_NAME'"
46
47