-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump.sh
executable file
·45 lines (31 loc) · 1.13 KB
/
bump.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
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Check if enough arguments were passed
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <monorepo-root-directory> <dependency-name> <new-version>"
exit 1
fi
# Arguments
monorepo_root=$1
dependency_name=$2
new_version=$3
# Find package.json files in the root of each microservice, excluding node_modules and nested directories
find "$monorepo_root" -mindepth 1 -maxdepth 2 -type f -name "package.json" -not -path "*/node_modules/*" | while read -r package_json; do
echo "Updating $dependency_name to version $new_version in $package_json"
# Update the dependency version using jq
jq --arg dep "$dependency_name" --arg ver "$new_version" \
'if .dependencies[$dep] then .dependencies[$dep] = $ver
elif .devDependencies[$dep] then .devDependencies[$dep] = $ver
else . end' "$package_json" > tmp.json && mv tmp.json "$package_json"
done
cd $monorepo_root
for d in */ ; do
echo "Updating packages in $d"
if [ -d "$d" ]; then
cd $d
yarn
echo "Completed Updating packages in $d"
cd ..
else
yarn && git status && echo "Completed Updating packages in $d"
fi
done