Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 54 additions & 34 deletions scripts/copy-poktroll-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ DIR="$(dirname "$0")"
if [ ! -d "$DIR" ]; then
DIR="$PWD"
fi
DIR="$(cd "$DIR" && pwd)"

. ${DIR}/shared.sh

Expand All @@ -14,41 +15,60 @@ if ! command -v ignite >/dev/null 2>&1; then
exit 1
fi

# Create a temp directory to clone poktroll into
WORK_DIR=$(mktemp -d -p "${DIR}")
# Normalize WORK_DIR to absolute path
WORK_DIR=$(cd "$WORK_DIR" && pwd)

if [ -z "$WORK_DIR" ]; then
echo "Could not create temp dir"
exit 1
fi

echo "Working in $WORK_DIR"

cleanup() {
info_log "Cleaning up..."
rm -rf "$WORK_DIR"
info_log "Cleanup done. Poktroll directory was deleted."
}

# Remove the temp directory on exit
trap cleanup EXIT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎


default_branch="main"
branch=${1:-$default_branch}

rm -rf poktroll
info_log "Poktroll github repository is going to be clone..."
cd ${WORK_DIR}

info_log "Cloning Poktroll from github.com/pokt-network/poktroll..."
git clone https://github.com/pokt-network/poktroll.git
{
info_log "Poktroll github repository is cloned..."
cd poktroll

if [ "$branch" != "$default_branch" ]; then
info_log "Poktroll github repository is going to be checkout to $branch branch..."
git checkout $branch
fi

info_log "TypeScript client files will be generated..."
echo "Y" | ignite generate ts-client --yes --use-cache

info_log "TypeScript client files were generated. Now copying them to the project..."
cd ..
rm -rf ${DIR}/../src/client
mkdir -p ${DIR}/../src/client

# Here we are copying the files from poktroll.application because every directory copied has the types directory with the same files inside.
cp -TR poktroll/ts-client/poktroll.application/types ${DIR}/../src/client
rm -f ${DIR}/../src/client/route-name.eta

info_log "TypeScript client files were copied. Now copying proto files..."

rm -rf ${DIR}/../proto/poktroll
mkdir -p ${DIR}/../proto/poktroll
cp -TR poktroll/proto/poktroll/ ${DIR}/../proto/poktroll
git add ${DIR}/../proto/poktroll

info_log "Proto files were copied."
rm -rf poktroll
info_log "Poktroll folder cloned from github was deleted."
} || rm -rf poktroll

info_log "Poktroll from github.com/pokt-network/poktroll was cloned."
cd poktroll

if [ "$branch" != "$default_branch" ]; then
info_log "Checking out $branch branch in Poktroll repository..."
git checkout $branch
fi

info_log "Generating TypeScript client files..."
echo "Y" | ignite generate ts-client --yes --use-cache

info_log "TypeScript client files were generated. Now copying them to the project..."
cd ${WORK_DIR}
# Deleting old TypeScript client files.
rm -rf ${DIR}/../src/client/*

# Here we are copying the files from poktroll.application because every directory has the types directory with the same files inside generated by ignite.
cp -TR poktroll/ts-client/poktroll.application/types ${DIR}/../src/client
rm -f ${DIR}/../src/client/route-name.eta

info_log "TypeScript client files were copied. Now copying proto files..."

# Deleting old protobuf source files.
rm -rf ${DIR}/../proto/poktroll/*
cp -TR poktroll/proto/poktroll/ ${DIR}/../proto/poktroll

info_log "Proto files were copied."

Loading