-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b9d0bc
commit 0c7ab83
Showing
3 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
get_latest_stable_nodejs_version() { | ||
local url="https://nodejs.org/dist/index.json" | ||
local temp_file=$(mktemp) | ||
|
||
# Download the JSON data | ||
if ! curl -s "$url" -o "$temp_file"; then | ||
echo "Failed to retrieve the latest stable version of Node.js" >&2 | ||
rm "$temp_file" | ||
return 1 | ||
fi | ||
|
||
# Parse JSON and find the latest stable (LTS) version | ||
local latest_version=$(jq -r ' | ||
map(select(.lts != false)) | ||
| sort_by(.date) | ||
| reverse | ||
| .[0].version | ||
' "$temp_file") | ||
|
||
rm "$temp_file" | ||
|
||
if [[ -n "$latest_version" ]]; then | ||
echo "$latest_version" | ||
else | ||
echo "Failed to parse the latest stable version of Node.js" >&2 | ||
return 1 | ||
fi | ||
} |