SHELL := /bin/bash
APP_DIR := $(PWD)/app
BRANCH ?= main
START_TIME := $(date +%s)

clean:
	rm -rf app

clone: clean
	sh static/scripts/clone_app.sh ${BRANCH}

install: clone
	cd app && NG_CLI_ANALYTICS="false" npm ci --unsafe-perm

assets: install
	cp -rf customizable/assets/. app/src/assets/ && cp -rf customizable/assets-mobile/. app/resources/

configuration-web: assets
	sh static/scripts/ionic.sh

configuration-android: assets
	CONFIG_MODE=ANDROID sh static/scripts/ionic.sh

configuration-ios: assets
	CONFIG_MODE=IOS sh static/scripts/ionic.sh

web-build: configuration-web
	cd app && ionic build --prod

web: web-build
	mkdir -p app/www/.well-known && source app.conf && sh static/scripts/universal_link_files.sh
	cd app/www && zip -r ../../www.zip .
	echo "Web application artifact for version ${VERSION} is archived in www.zip"

prepare-android: configuration-android
	source app.conf && cd app && rm -rf android www && ionic capacitor add android && npm run resources:android && ionic capacitor build android --no-open --prod  && cd .. && sh static/scripts/android.sh
	cp -rf static/fastlane-android/. app/android/fastlane/ && cp -rf app.conf app/android/.env

android: prepare-android
	cd app/android && bundler exec fastlane android release

android-beta: prepare-android
	cd app/android && bundler exec fastlane android beta

prepare-ios: configuration-ios
	source app.conf && cd app && rm -rf ios www && ionic capacitor add ios && npm run resources:ios && ionic capacitor build ios --no-open --prod  && cd .. && sh static/scripts/ios.sh
	cp -rf static/fastlane-ios/. app/ios/App/fastlane/ && cp -rf app.conf app/ios/App/fastlane/.env

ios: prepare-ios 
	cd app/ios/App && bundler exec fastlane ios release

ios-beta: prepare-ios
	cd app/ios/App && bundler exec fastlane ios beta
