budibase/scripts/removeWorkspaceDependencies.sh

52 lines
1.3 KiB
Bash
Raw Normal View History

2023-10-02 18:18:42 +02:00
#!/bin/bash
2023-10-03 11:02:11 +02:00
2023-10-13 13:59:42 +02:00
packages_to_remove=(
@budibase/backend-core
@budibase/bbui
@budibase/builder
@budibase/cli
@budibase/client
@budibase/frontend-core
@budibase/pro
@budibase/sdk
@budibase/server
@budibase/shared-core
# We cannot remove string-templates yet because it cannot be bundled by esbuild as a dependency
@budibase/string-templates
@budibase/types
@budibase/worker
)
2023-10-03 11:02:11 +02:00
2023-10-02 18:18:42 +02:00
root_package_json=$(cat "package.json")
2023-10-03 09:34:35 +02:00
process_package() {
local pkg="$1"
local package_json=$(cat "$pkg/package.json")
local has_changes=false
2023-10-02 18:18:42 +02:00
2023-10-13 13:59:42 +02:00
for package_name in "${packages_to_remove[@]}"; do
2023-10-03 09:34:35 +02: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
2023-10-13 13:59:42 +02:00
done
2023-10-02 18:18:42 +02:00
2023-10-03 09:34:35 +02:00
if [ "$has_changes" = true ]; then
echo "$package_json" > "$1/package.json"
2023-10-02 18:18:42 +02:00
fi
2023-10-03 09:34:35 +02:00
}
2023-10-02 18:18:42 +02:00
2023-10-03 09:34:35 +02: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-02 18:18:42 +02:00
fi
done
echo "$root_package_json" | jq "del(.resolutions)" > "package.json"