#!/bin/bash

COMMIT=$(git show --pretty=format:%s -s HEAD)
# Set the build number on android and iOS
BUILD_NUMBER=$(git show -s --format=%ct)
# Semantic release will auto bump package.json so ensure ios and android use the same version
PACKAGE_VERSION=$(cat ../package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')

echo "Setting build number to $BUILD_NUMBER"
plutil -replace CFBundleVersion -string $BUILD_NUMBER ../ios/lightbaseTemplate/Info.plist
sed -i '' 's/versionCode=.*/versionCode='$BUILD_NUMBER'/' ../android/gradle.properties

echo "Setting app version number to $PACKAGE_VERSION"
plutil -replace CFBundleShortVersionString -string $PACKAGE_VERSION ../ios/lightbaseTemplate/Info.plist
sed -i '' 's/versionName=.*/versionName='$PACKAGE_VERSION'/' ../android/gradle.properties

echo -ne '\nBUILD_NUMBER='$BUILD_NUMBER'' >> ../.env.production

cat ../.env.production

