diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 1ad1c9f..0f2f795 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -137,9 +137,7 @@ private_lane :buildConfiguration do |options| installDependencies(options) - unless options[:features].nil? - generate_enabled_features_extension(options) - end + generate_enabled_features_extension_if_needed(options) if !(options[:uploadToFabric] || options[:uploadToAppStore]) options[:skip_package_ipa] = true @@ -402,20 +400,32 @@ def get_google_services_plist_path(app_target_folder_name, configuration_type) File.expand_path "../#{app_target_folder_name}/Resources/#{configuration_type.prefix}-GoogleService-Info.plist" end -def generate_enabled_features_extension(options) +def generate_enabled_features_extension_if_needed(options) app_target_folder_name = options[:appName] || $appName - project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features/Enabled.swift" + project_enabled_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features/Enabled.swift" build_settings_file_path = File.expand_path "../common/build_settings.yaml" - builder_features_list = options[:features] - .split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] + unless is_feature_extension_needed?(options, project_enabled_features_file_path) + return + end + + if options[:features].nil? + builder_features_list = [] # If Enabled.swift exists and features option is nil we need to create empty extension to avoid unexpected features + else + builder_features_list = (options[:features] || []) + .split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] + end build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] - enabled_features_hash = Touchlane::Features.generate_enabled_features_hash(builder_features_list, build_settings_features_list) + enabled_features_extension = Touchlane::Features.generate_enabled_features_extension(builder_features_list, build_settings_features_list) - Managers::FileManager.save_data_to_file_in_json(project_features_file_path, features_hash) + Managers::FileManager.save_data_to_file(project_enabled_features_file_path, enabled_features_extension) +end + +def is_feature_extension_needed?(options, project_enabled_features_file_path) + !options[:features].nil? || File.exists?(project_enabled_features_file_path) end def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 37b0f29..838eb0e 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -4,12 +4,12 @@ require_relative '../../../../templates/templates' module Touchlane class Features - def self.generate_enabled_features_hash(builder_features_list, build_settings_features_list) + def self.generate_enabled_features_extension(builder_features_list, build_settings_features_list) # Check is entered features contains in configuration file features_diff = builder_features_list - build_settings_features_list - if !features_diff.empty? + unless features_diff.empty? raise "Unexpected features: " + features_diff.join(', ') end @@ -17,7 +17,7 @@ module Touchlane enabled_features_extension_template = Templates::FeatureTemplates.enabled_features_extension utils = Managers::TemplateManager.new(builder_features_list) - utils.render(enabled_features_extension_template).strip.to_hash() + utils.render(enabled_features_extension_template).strip end private_class_method :new diff --git a/xcode/templates/templates/features_templates.rb b/xcode/templates/templates/features_templates.rb index 9c7cb44..ee049cf 100755 --- a/xcode/templates/templates/features_templates.rb +++ b/xcode/templates/templates/features_templates.rb @@ -22,7 +22,7 @@ public extension Feature { static var enabled: [Feature] { [ <% for @item in @items %> - .<%= @item %>, + \.<%= @item %>, <% end %> ] }