#!/usr/bin/env bash
# @author juntao
# @2019.09.19

version=$(awk -v FS="versionName = " 'NF>1{print $2}' dependencies.gradle | sed "s/\"//g")
build_time=$(TZ=Asia/Shanghai date +'%Y-%m%d-%H%M')
build_time_without_divider=$(TZ=Asia/Shanghai date +'%Y%m%d%H%M')L

git checkout module_common/build.gradle
git checkout gradle.properties

sed -i '/debugApi "com.lg:chucker:${chucker}"/c\    api "com.lg:chucker:${chucker}"' module_common/build.gradle
sed -i '/releaseApi "com.lg:chucker-no-op:${chucker}"/c\' module_common/build.gradle

./gradlew --stop
./gradlew clean

sed -i "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=1/g" gradle.properties
sed -i 's/buildConfigField "long", "BUILD_TIME", "0"/buildConfigField "long", "BUILD_TIME", '"\"$build_time_without_divider\""'/g' module_common/build.gradle

./gradlew rIR -I init.gradle
mv app/build/outputs/apk/internal/release/app-internal-release.apk app/build/outputs/apk/internal/release/光环助手$version-带请求日志-$build_time.apk

git checkout module_common/build.gradle
git checkout gradle.properties