Last active
March 27, 2025 19:18
-
-
Save denoww/ae54235bb132c105aff5b8b47bd30ebe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Como Usar | |
# ruby ios_criar_flavor.rb flex2 "Flex 2" br.com.flex2 | |
# ruby ios_criar_flavor.rb flex3 "Flex 3" br.com.flex3 | |
# Como Usar | |
# ruby ios_criar_flavor.rb flex2 "Flex 2" br.com.flex2 | |
# ruby ios_criar_flavor.rb flex3 "Flex 3" br.com.flex3 | |
require 'xcodeproj' | |
require 'fileutils' | |
require 'rexml/document' | |
if ARGV.length != 3 | |
puts "Uso: ruby ios_criar_flavor.rb <nome> <display_name> <product_bundle_identifier>" | |
exit | |
end | |
flavor = ARGV[0] | |
display_name = ARGV[1] | |
product_bundle_identifier = ARGV[2] | |
project_path = '/Users/seucondominio/workspace/erp_flutter/ios/Runner.xcodeproj' | |
scheme_dir = File.join(project_path, 'xcshareddata', 'xcschemes') | |
scheme_file = File.join(scheme_dir, "#{flavor}.xcscheme") | |
def clonar_target_config(flavor, product_bundle_identifier, display_name, tipo, clonar_config_de, target) | |
tipo = tipo.to_s | |
flavor_tipo = "#{flavor}-#{tipo}" | |
old_config = target.build_configurations.find { |config| config.name == "#{clonar_config_de}-#{tipo}" } | |
return unless old_config | |
new_config = target.add_build_configuration(flavor_tipo, tipo.to_sym) | |
# new_config = target.build_configurations.find { |config| config.name == flavor_tipo } | |
new_config.build_settings.update(old_config.build_settings) | |
new_config.base_configuration_reference = old_config.base_configuration_reference | |
new_config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = "AppIcon-#{flavor}" | |
new_config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = product_bundle_identifier | |
new_config.build_settings['APP_DISPLAY_NAME'] = display_name | |
end | |
def clonar_project_config(flavor, project, clonar_config_de, tipo) | |
from = "#{clonar_config_de}-#{tipo}" | |
to = "#{flavor}-#{tipo}" | |
old_config = project.build_configurations.find { |c| c.name == from } | |
return unless old_config | |
new_config = project.add_build_configuration(to, tipo.to_sym) | |
new_config.build_settings.update(old_config.build_settings) | |
new_config.base_configuration_reference = old_config.base_configuration_reference | |
end | |
# def criar_scheme(flavor, scheme_dir, scheme_file) | |
# FileUtils.mkdir_p(scheme_dir) | |
# doc = REXML::Document.new | |
# doc << REXML::XMLDecl.new | |
# scheme = doc.add_element('Scheme', { | |
# 'LastUpgradeVersion' => '1330', | |
# 'version' => '1.7' | |
# }) | |
# build_action = scheme.add_element('BuildAction', { | |
# 'parallelizeBuildables' => 'YES', | |
# 'buildImplicitDependencies' => 'YES' | |
# }) | |
# entry = build_action.add_element('BuildActionEntries') | |
# entry.add_element('BuildActionEntry', { | |
# 'buildForTesting' => 'YES', | |
# 'buildForRunning' => 'YES', | |
# 'buildForProfiling' => 'YES', | |
# 'buildForArchiving' => 'YES', | |
# 'buildForAnalyzing' => 'YES' | |
# }).add_element('BuildableReference', { | |
# 'BuildableIdentifier' => 'primary', | |
# 'BlueprintIdentifier' => 'Runner', | |
# 'BuildableName' => 'Runner.app', | |
# 'BlueprintName' => 'Runner', | |
# 'ReferencedContainer' => 'container:Runner.xcodeproj' | |
# }) | |
# scheme.add_element('TestAction', { | |
# 'buildConfiguration' => "#{flavor}-debug", | |
# 'selectedDebuggerIdentifier' => 'Xcode.DebuggerFoundation.Debugger.LLDB', | |
# 'selectedLauncherIdentifier' => 'Xcode.DebuggerFoundation.Launcher.LLDB', | |
# 'shouldUseLaunchSchemeArgsEnv' => 'YES' | |
# }).add_element('Testables') | |
# scheme.add_element('LaunchAction', { | |
# 'buildConfiguration' => "#{flavor}-debug", | |
# 'selectedDebuggerIdentifier' => 'Xcode.DebuggerFoundation.Debugger.LLDB', | |
# 'selectedLauncherIdentifier' => 'Xcode.DebuggerFoundation.Launcher.LLDB', | |
# 'launchStyle' => '0', | |
# 'useCustomWorkingDirectory' => 'NO', | |
# 'ignoresPersistentStateOnLaunch' => 'NO', | |
# 'debugDocumentVersioning' => 'YES', | |
# 'allowLocationSimulation' => 'YES' | |
# }).add_element('BuildableProductRunnable').add_element('BuildableReference', { | |
# 'BuildableIdentifier' => 'primary', | |
# 'BlueprintIdentifier' => 'Runner', | |
# 'BuildableName' => 'Runner.app', | |
# 'BlueprintName' => 'Runner', | |
# 'ReferencedContainer' => 'container:Runner.xcodeproj' | |
# }) | |
# scheme.add_element('ProfileAction', { | |
# 'buildConfiguration' => "#{flavor}-release", | |
# 'shouldUseLaunchSchemeArgsEnv' => 'YES', | |
# 'savedToolIdentifier' => '', | |
# 'useCustomWorkingDirectory' => 'NO', | |
# 'debugDocumentVersioning' => 'YES' | |
# }).add_element('BuildableProductRunnable').add_element('BuildableReference', { | |
# 'BuildableIdentifier' => 'primary', | |
# 'BlueprintIdentifier' => 'Runner', | |
# 'BuildableName' => 'Runner.app', | |
# 'BlueprintName' => 'Runner', | |
# 'ReferencedContainer' => 'container:Runner.xcodeproj' | |
# }) | |
# scheme.add_element('AnalyzeAction', { | |
# 'buildConfiguration' => "#{flavor}-debug" | |
# }) | |
# scheme.add_element('ArchiveAction', { | |
# 'buildConfiguration' => "#{flavor}-release", | |
# 'revealArchiveInOrganizer' => 'YES' | |
# }) | |
# File.write(scheme_file, doc.to_s) | |
# puts "✅ Scheme compartilhado criado: #{scheme_file}" | |
# end | |
def criar_flavor(flavor, display_name, product_bundle_identifier, project_path, scheme_dir, scheme_file) | |
project = Xcodeproj::Project.open(project_path) | |
clonar_config_de = 'ficbrasile' | |
%w[debug release].each do |tipo| | |
project.targets.each do |target| | |
clonar_target_config(flavor, product_bundle_identifier, display_name, tipo, clonar_config_de, target) | |
end | |
clonar_project_config(flavor, project, clonar_config_de, tipo) | |
end | |
project.save | |
# criar_scheme(flavor, scheme_dir, scheme_file) | |
end | |
criar_flavor(flavor, display_name, product_bundle_identifier, project_path, scheme_dir, scheme_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment