-
-
Save EgzonArifi/1beafd76c4d67a51fc8356a6211d210f to your computer and use it in GitHub Desktop.
Update .local.xcconfig files from .env files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
ENV_NAME="$1" | |
if [ -z "$ENV_NAME" ]; then | |
echo "Error: Missing required environment name argument." | |
exit 1 | |
fi | |
# Get the script's directory | |
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |
configs_dir="${script_dir}/../../YourProject/Configs" | |
ENV_FILE="${configs_dir}/.env.${ENV_NAME}" | |
CONFIG_FILE="${configs_dir}/Config$(echo ${ENV_NAME:0:1} | tr "[:lower:]" "[:upper:]")${ENV_NAME:1}.xcconfig" | |
LOCAL_CONFIG_FILE="${CONFIG_FILE%.*}.local.xcconfig" | |
# Load the environment variables from the .env file | |
export $(grep -v "^#" $ENV_FILE | xargs) | |
# Define arrays for keys and values | |
KEYS=("API_KEY" "SDK_LICENSE_KEY") | |
VALUES=("${API_KEY}" "${SDK_LICENSE_KEY}") | |
# Copy the original .xcconfig file to a .xcconfig.local file | |
cp "$CONFIG_FILE" "$LOCAL_CONFIG_FILE" | |
# Iterate through the keys and replace the placeholders in the .xcconfig.local file | |
for i in "${!KEYS[@]}"; do | |
key="${KEYS[$i]}" | |
value="${VALUES[$i]}" | |
if [ -z "$value" ]; then | |
echo "Error: Missing value for environment variable $key" | |
exit 1 | |
fi | |
sed -i '' "s/${key}_PLACEHOLDER/${value}/g" "${LOCAL_CONFIG_FILE}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment