-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
32 lines (26 loc) · 876 Bytes
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# On Windows run e.g. 'choco install jq' within an admin shell
if ! command -v jq > /dev/null 2>&1; then
echo "Error: 'jq' is not installed."
exit 1
fi
PACKAGE_JSON="package.json"
if [ ! -f "$PACKAGE_JSON" ]; then
echo "package.json not found!"
exit 1
fi
# The old way of getting dependencies without 'jq'
# DEPENDENCIES=$(cat package.json | grep -Po '"[^"]*":\s*"\^[^"]*"' | cut -d '"' -f 2)
# Extract dependencies and devDependencies using jq, and trim whitespace
DEPENDENCIES=$(jq -r '
[(.dependencies // {} | keys[]), (.devDependencies // {} | keys[])]
| flatten
| .[]
' "$PACKAGE_JSON" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Loop through each dependency and update it
echo "$DEPENDENCIES" | while read -r PACKAGE; do
if [[ -n "$PACKAGE" ]]; then
echo "Now updating: '$PACKAGE'..."
npm install "$PACKAGE"@latest
fi
done