Dir[File.expand_path('scripts/*.rb', __dir__)].each { |file| require_relative file } Dir[File.expand_path('platform/android/*.rb', __dir__)].each { |file| require_relative file } Dir[File.expand_path('platform/ios/*.rb', __dir__)].each { |file| require_relative file } Dir[File.expand_path('platform/flutter/*.rb', __dir__)].each { |file| require_relative file } class BrandSwitcher def initialize(brand_key, ignore_health_check: false) Solara.logger.debug("ignore_health_check = #{ignore_health_check}") @brand_key = brand_key @ignore_health_check = ignore_health_check @platform = SolaraSettingsManager.instance.platform end def self.switch_to_first_brand(ignore_health_check: true) first_brand_key = BrandsManager.instance.first_brand_key if first_brand_key.nil? return end BrandSwitcher.new(first_brand_key, ignore_health_check: ignore_health_check).start end def start Solara.logger.header("Switching to #{@brand_key}") health_errors = SolaraManager.new.doctor([@brand_key]).select { |issue| issue.type == Issue::ERROR } unless health_errors.empty? unless @ignore_health_check errors_with_index = health_errors.each_with_index.map { |error, index| "#{index + 1}: #{error}" } raise "Health check completed with errors: \n\n#{errors_with_index.join("\n")}." end end BrandsManager.instance.save_current_brand(@brand_key) Solara.logger.start_step("Create artifacts directories") create_artifacts_dirs Solara.logger.end_step("Create artifacts directories") switch SolaraConfigurator.new.start Solara.logger.success("Switched to #{@brand_key} successfully.") end def create_artifacts_dirs case @platform when Platform::Flutter directories = [ FilePath::flutter_artifacts, FilePath::android_artifacts, IOSFilePathManager.instance.artifacts ] DirectoryCreator.create_directories(directories, delete_if_exists: true) when Platform::IOS directories = [ IOSFilePathManager.instance.artifacts ] DirectoryCreator.create_directories(directories, delete_if_exists: true) when Platform::Android directories = [ FilePath::android_artifacts ] DirectoryCreator.create_directories(directories, delete_if_exists: true) else raise ArgumentError, "Invalid platform: #{@platform}" end end def switch case @platform when Platform::Flutter switch_flutter switch_android switch_ios when Platform::IOS switch_ios when Platform::Android switch_android else raise ArgumentError, "Invalid platform: #{@platform}" end end def generate_theme_kotlin generate_theme( 'BrandTheme.kt', Language::Kotlin, Platform::Android) end def generate_theme_swift generate_theme( 'BrandTheme.swift', Language::Swift, Platform::IOS) end def generate_theme_dart generate_theme( 'brand_theme.dart', Language::Dart, Platform::Flutter) end def generate_theme( name, language, platform) Solara.logger.start_step("Generate #{language} theme for #{platform}") generator = ThemeGenerator.new( FilePath.brand_theme(@brand_key), FilePath.generated_config(name, platform), language) generator.generate Solara.logger.end_step("Generate #{language} theme for #{platform}") end def generate_app_config_kotlin generate_brand_config( 'BrandConfig.kt', Language::Kotlin, Platform::Android ) end def generate_app_config_swift generate_brand_config( 'BrandConfig.swift', Language::Swift, Platform::IOS) end def generate_app_config_dart generate_brand_config( 'brand_config.dart', Language::Dart, Platform::Flutter) end def generate_brand_config( name, language, platform) BrandConfigManager.new(@brand_key).generate_brand_config( name, language, platform) end def switch_flutter generate_theme_dart generate_app_config_dart BrandResourcesManager.new(@brand_key).update_flutter end def switch_android BrandConfigManager.new(@brand_key).generate_android_properties config_path = FilePath.android_brand_config(@brand_key) config = JSON.parse(File.read(config_path)) update_build_gradle update_manifest(config) update_strings_xml(config) BrandResourcesManager.new(@brand_key).update_android generate_theme_kotlin generate_app_config_kotlin end def update_build_gradle switcher = GradleSwitcher.new(@brand_key) switcher.update_build_gradle end def update_manifest(config) switcher = AndroidManifestSwitcher.new switcher.update_manifest(config) end def update_strings_xml(config) switcher = AndroidStringsSwitcher.new switcher.update(config) end def switch_ios BrandConfigManager.new(@brand_key).generate_ios_xcconfig generate_theme_swift generate_app_config_swift update_xcode_project BrandResourcesManager.new(@brand_key).update_ios end def update_xcode_project Solara.logger.start_step("Update Xcode project") project_path = IOSFilePathManager.instance.xcode_project switcher = XcodeProjectSwitcher.new(project_path, @brand_key) switcher.switch Solara.logger.end_step("Update Xcode project") end end