-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-packages.bash
More file actions
58 lines (40 loc) · 1.35 KB
/
update-packages.bash
File metadata and controls
58 lines (40 loc) · 1.35 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Список пакетов, которые нужно исключить из обновления
EXCLUDE_PACKAGES=("react" "react-dom" "typescript")
DEPS=$(tr -d '\n' <package.json | grep -o '"dependencies": {[^}]*}' | grep -E -o '"[^"]+": *"[^"]+"' | sed 's/": *"[^"]*//;s/"//g')
DEV_DEPS=$(tr -d '\n' <package.json | grep -o '"devDependencies": {[^}]*}' | grep -E -o '"[^"]+": *"[^"]+"' | sed 's/": *"[^"]*//;s/"//g')
is_excluded() {
local package=$1
for excluded in "${EXCLUDE_PACKAGES[@]}"; do
if [[ "$excluded" == "$package" ]]; then
return 0 # Это пакет в исключениях
fi
done
return 1 # Пакет не в исключениях
}
get_packages() {
old_ifs="$IFS"
local pkg=$(echo "$1" | tr '\n' ' ')
parts=($pkg)
IFS=' '
IFS="$old_ifs"
result_packages=""
for part in "${parts[@]}"; do
if ! is_excluded "$part"; then
result_packages+=" $part"
fi
done
output_string=$(echo "$result_packages" | sed 's/^\s//' | tr '\n' ' ' | sed 's/[[:space:]]\+$//' | sed 's/\([^ ]*\)/\1@latest/g')
echo "$output_string"
}
update_dependencies() {
local _deps=$(get_packages "$DEPS")
echo "pnpm install -P $_deps" | sh
}
update_devDependencies() {
local _deps=$(get_packages "$DEV_DEPS")
echo "pnpm install -D $_deps" | sh
}
update_dependencies
update_devDependencies
echo "Done!"