Skip to content

Instantly share code, notes, and snippets.

@denoww
Last active June 25, 2024 20:30
Show Gist options
  • Save denoww/ae54235bb132c105aff5b8b47bd30ebe to your computer and use it in GitHub Desktop.
Save denoww/ae54235bb132c105aff5b8b47bd30ebe to your computer and use it in GitHub Desktop.
# Como Usar
# ios_criar_flavor.rb flex2 "Flex 2" br.com.flex2
# ios_criar_flavor.rb flex3 "Flex 3" br.com.flex3
# editar essa lib
# sudo subl ~/Downloads/ios_criar_flavor.rb
# ou
# sudo code ~/Downloads/ios_criar_flavor.rb
# Salvar em
# https://gist.github.com/denoww/ae54235bb132c105aff5b8b47bd30ebe/edit
project_path = '/Users/seucondominio/workspace/erp_flutter/ios/Runner.xcodeproj'
clonar_config_de = 'ficbrasile'
require 'xcodeproj'
# Verifica se o nome da configuração e os outros parâmetros foram passados como argumentos
if ARGV.length != 3
puts "Uso: ruby criarconfig.rb <nome> <product_bundle_identifier> <display_name>"
exit
end
flavor = ARGV[0]
product_bundle_identifier = ARGV[2]
display_name = ARGV[1]
def clonar_config(opt)
flavor_tipo = "#{opt[:flavor]}-#{opt[:tipo]}"
config_to_copy = opt[:target].build_configurations.find { |config| config.name == "#{opt[:clonar_config_de]}-#{opt[:tipo]}" }
return unless config_to_copy
config = opt[:target].add_build_configuration(flavor_tipo, opt[:tipo.to_sym])
config.build_settings.update(config_to_copy.build_settings)
config.base_configuration_reference = config_to_copy.base_configuration_reference
set_config config, opt
end
def update_config(opt)
config = opt[:target].build_configurations.find { |config| config.name == "#{opt[:flavor]}-#{opt[:tipo]}" }
set_config config, opt
end
def set_config config, opt
# Atualiza o nome do ícone do app
app_icon_name = "AppIcon-#{opt[:flavor]}"
config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = app_icon_name
# Atualiza o product bundle identifier
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = opt[:product_bundle_identifier]
# Atualiza o app display name
config.build_settings['APP_DISPLAY_NAME'] = opt[:display_name]
end
def criar_flavor(opt)
project = Xcodeproj::Project.open(opt[:project_path])
project.targets.each do |target|
opt[:target] = target
update_config(opt.merge(tipo: 'debug'))
update_config(opt.merge(tipo: 'release'))
# clonar_config(opt.merge(tipo: 'debug'))
# clonar_config(opt.merge(tipo: 'release'))
end
project.save
end
opt = {
flavor: flavor,
product_bundle_identifier: product_bundle_identifier,
display_name: display_name,
project_path: project_path,
clonar_config_de: clonar_config_de,
}
criar_flavor(opt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment