#!/bin/bash

VERSION_AND_CODE="$(cat pubspec.yaml  | grep 'version:' | sed 's/version: //')"
VERISON_NAME="$(echo $VERSION_AND_CODE | cut -d+ -f1)"
VERSION_CODE="$(echo $VERSION_AND_CODE | cut -d+ -f2)"

NEW_VERSION_CODE="$(( $VERSION_CODE + 1 ))"
sed -i "s/^version: .*$/version: ${VERISON_NAME}+${NEW_VERSION_CODE}/" pubspec.yaml

echo "Update pubspec for version ${VERISON_NAME}+${NEW_VERSION_CODE}"
exit $VERSION_CODE
