Skip to content

Instantly share code, notes, and snippets.

@cball
Last active April 13, 2024 21:04
Show Gist options
  • Save cball/8a26d1d8ed72f9f76fe9810b9b48e441 to your computer and use it in GitHub Desktop.
Save cball/8a26d1d8ed72f9f76fe9810b9b48e441 to your computer and use it in GitHub Desktop.
Fastlane file for updating ids, display names, and icons w/ badges in React Native
# this should be the folder name under `ios` for your project
project_name = 'MyProject'
# NOTE: This is meant to be run on CI where it changes everything before building the app.
# Usage:
# `RN_RELEASE_TYPE=beta fastlane prep_release_type` (on CI these ENV variables should be set via the UI)
# Available release types: alpha, beta, production (default)
#
# If you're trying this script out locally, make sure you have ImageMagick installed, and discard the changes via git when you're done.
desc "Updates the app identifier, display name and icon for alpha, beta, and production releases"
lane :prep_release_type do
# alpha, beta, production
type = ENV['RN_RELEASE_TYPE'] || 'production'
next if type == 'production'
suffix = ENV['RN_BUNDLE_SUFFIX'] || type
# assumes identifier is defined in Appfile
app_id = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
new_app_id = "#{app_id}.#{suffix}"
display_name = ENV['RN_DISPLAY_NAME'] || type.capitalize
UI.message "\n\nSetting app identifier to: #{new_app_id}"
UI.message "\n\nSetting Display Name to: #{display_name}"
# update ios indentifier and display name
update_info_plist(
plist_path: "#{project_name}/Info.plist",
xcodeproj: "./ios/#{project_name}.xcodeproj",
display_name: display_name,
app_identifier: new_app_id
)
# update android display name
update_android_strings(
block: lambda { |strings|
strings['app_name'] = display_name
}
)
# update android suffix
set_value_in_build(
app_project_dir: "./android/app",
key: "applicationIdSuffix",
value: ".#{suffix}"
)
# Add badge to app icon
# want to add the app version to the icon? try this:
# current_version = get_version_number(xcodeproj: "./ios/#{project_name}.xcodeproj", target: project_name)
# add_badge(
# shield: "Version-#{current_version}-blue"
# shield_scale: 0.75
# )
#
# See all available options at: https://github.com/HazAT/badge
UI.message "\n\nUpdating app icon with #{type} badge"
# ios badge
add_badge(
# use dark if your icon is light in color
# dark: true,
glob: "/ios/**/*.appiconset/*.{png,PNG}", # note no dot in path
alpha: type == 'alpha',
grayscale: type == 'alpha'
)
# android badge
add_badge(
# use dark if your icon is light in color
# dark: true,
glob: "/android/app/src/main/res/**/*.{png,PNG}", # note no dot in path
alpha: type == 'alpha',
grayscale: type == 'alpha'
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment