1
0
Fork 0
mirror of synced 2024-09-17 17:57:47 +12:00
budibase/scripts/removeWorkspaceDependencies.sh

62 lines
1.4 KiB
Bash
Raw Normal View History

2023-10-03 05:18:42 +13:00
#!/bin/bash
2023-10-03 22:02:11 +13:00
exclude_packages=()
while getopts "e:" opt; do
case $opt in
e)
exclude_packages+=("$OPTARG")
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
2023-10-03 05:18:42 +13:00
root_package_json=$(cat "package.json")
2023-10-03 20:34:35 +13:00
process_package() {
local pkg="$1"
local package_json=$(cat "$pkg/package.json")
local has_changes=false
2023-10-03 05:18:42 +13:00
2023-10-03 20:34:35 +13:00
2023-10-03 05:18:42 +13:00
2023-10-03 20:34:35 +13:00
while IFS= read -r package_name; do
2023-10-03 22:02:11 +13:00
for exclude_package in "${exclude_packages[@]}"; do
if [ "$package_name" == "$exclude_package" ]; then
continue 2 # Skip this package and continue with the next one
fi
done
2023-10-03 20:34:35 +13:00
if echo "$package_json" | jq -e --arg package_name "$package_name" '.dependencies | has($package_name)' > /dev/null; then
package_json=$(echo "$package_json" | jq "del(.dependencies[\"$package_name\"])")
has_changes=true
fi
done < "packageNames.txt"
2023-10-03 05:18:42 +13:00
2023-10-03 20:34:35 +13:00
if [ "$has_changes" = true ]; then
echo "$package_json" > "$1/package.json"
2023-10-03 05:18:42 +13:00
fi
2023-10-03 20:34:35 +13:00
}
2023-10-03 05:18:42 +13:00
2023-10-03 20:34:35 +13:00
for pkg in $(echo "$root_package_json" | jq -r '.workspaces.packages[]' ); do
if [[ "$pkg" == *"*"* ]]; then
# Use find to iterate through immediate subdirectories
find "$pkg" -maxdepth 1 -type d -print | while read -r workspace_package; do
process_package "$workspace_package"
done
else
process_package "$pkg"
2023-10-03 05:18:42 +13:00
fi
done
echo "$root_package_json" | jq "del(.resolutions)" > "package.json"