Forked from lordcodes/sourcery-generate-app-secrets.sh
Created
September 11, 2021 17:39
-
-
Save saroar/b47cf3e1f074b0ba9b2045359eca53e2 to your computer and use it in GitHub Desktop.
Read secrets into your iOS project from xcconfig files and then use Sourcery to generate a source file to use them within your code.
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 | |
# Generate list of arguments to pass to Sourcery | |
function sourceryArguments { | |
# Environment variables from BuildConfig to map into AppSecrets | |
local arguments=( | |
"CHAT_API_CLIENT_SECRET" "ANALYTICS_WRITE_KEY" | |
) | |
local combinedArgs | |
local argumentsIndices=${!arguments[*]} | |
for index in $argumentsIndices | |
do | |
# Make the arguments list comma-separated | |
if [ $index -gt 0 ]; | |
then | |
combinedArgs="${combinedArgs}," | |
fi | |
# Append the argument name and escaped argument value | |
local argument=${arguments[$index]} | |
local argumentName="${argument}" | |
local argumentValue="\"${!argument}\"" | |
local argumentPair="${argumentName}=${argumentValue}" | |
combinedArgs="${combinedArgs}${argumentPair}" | |
done | |
echo $combinedArgs | |
} | |
sourceryArgs=$(sourceryArguments) | |
# Generate AppSecrets using the arguments list created above | |
mkdir -p Generated/Sourcery | |
Tools/Sourcery/bin/sourcery --sources ChatApp/Sources \ | |
--templates Templates/AppSecrets.stencil \ | |
--output Generated/Sourcery \ | |
--args $sourceryArgs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment