#!/bin/bash
set -eu
# This is a backwards compatibility script. All logic has moved to '@aws-cdk-testing/cli-integ'
# and should be called from there directly in the future.

# The package MUST be 'npm install'ed from the package repository (`npm install --production`
# will not work because that will resolve devDependencies even though it will not install them),
# but it may not live in a 'node_modules' directory because Jest 27 does not support that. Do contortions.
export INTEG_TOOLS=cli_integ
rm -rf $INTEG_TOOLS && mkdir $INTEG_TOOLS
npm install --prefix $INTEG_TOOLS --no-save @aws-cdk-testing/cli-integ@${RELEASE_TAG:-latest}
mv $($INTEG_TOOLS/node_modules/.bin/test-root)/* $INTEG_TOOLS

# Find the latest CLI version in this tag
npm view aws-cdk@${RELEASE_TAG:-latest} --json > release.json
export VERSION=$(node -pe "require('./release.json').version")

exec "$@"
