#!/bin/sh -eu

echo '
WARNING:

    This script aggressively updates all packages to the latest version.
    Be sure to run tests & check the application after this!

'

cd "$RUN_DIR"

[ -z "${DEBUG:-}" ] || set -x


# Poetry

poetry update --with=build,dev

poetry show --outdated --top-level \
| cut -d ' ' -f 1 \
| while read -r pkg; do
    poetry add "$pkg@latest"
done

poetry show --outdated --top-level --only=build \
| cut -d ' ' -f 1 \
| while read -r pkg; do
    poetry add --group=build "$pkg@latest"
done

poetry show --outdated --top-level --only=dev \
| cut -d ' ' -f 1 \
| while read -r pkg; do
    poetry add --group=dev "$pkg@latest"
done


# Npm

cd unwind-ui
npm update
npm install $(npm outdated --json --silent | jq -r 'keys|map("\(.)@latest")|@sh')

npm outdated --json --silent \
| jq -r 'keys|map(@sh"\(.)@latest")|join("\n")' \
| xargs npm install
