diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 3d82867..ac4eb16 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -106,24 +106,15 @@ private_lane :addShield do |options| end end -private_lane :uploadFeaturesToProject do |options| - require 'json' - - features_string = options[:features] # "DebitCardFeature,Sprint5Feature,CreditCardFeature" - feature_names = features_string.split(",").map { |value| value.strip } # [ "DebitCardFeature", "Sprint5Feature", "CreditCardFeature" ] - - # Generate JSON from feature names - feature_bodies = feature_names.map { |feature_name| { :name => feature_name, :enabled => true} } - features = { :features => features_body } - features_json = JSON.pretty_generate(features) - - # Put features JSON to project file +private_lane lane :uploadFeaturesToProject do |options| app_target_folder_name = options[:appName] || $appName - features_file_path = get_features_file_path(app_target_folder_name) - File.open(features_file_path, "w") do |f| - f.write(features_json) - end + project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features.json" + common_features_file_path = File.expand_path "../common/build_options/Features.json" + + builder_features_list = options[:features] # [ "Feature1", "Feature2", "Feature3" ] + + Touchlane::Features.generate_features_file_in_project(builder_features_list, common_features_file_path, project_features_file_path) end private_lane :buildConfiguration do |options| @@ -421,10 +412,6 @@ 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 get_features_file_path(app_target_folder_name) - File.expand_path "../#{app_target_folder_name}/Resources/Features.json" -end - def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) require 'xcodeproj' diff --git a/xcode/fastlane/touchlane/lib/touchlane.rb b/xcode/fastlane/touchlane/lib/touchlane.rb index f366ab1..7ece7cd 100644 --- a/xcode/fastlane/touchlane/lib/touchlane.rb +++ b/xcode/fastlane/touchlane/lib/touchlane.rb @@ -1,5 +1,6 @@ module Touchlane require_relative "touchlane/configuration_type" require_relative "touchlane/configuration" + require_relative "touchlane/features" require_relative "match/storage/local_storage" -end \ No newline at end of file +end diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb new file mode 100644 index 0000000..3c50022 --- /dev/null +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -0,0 +1,41 @@ +require 'json' +require 'yaml' + +module Touchlane + class Features + + def self.generate_features_file_in_project(builder_features_list, common_features_file_path, project_features_file_path) + common_features_list = get_features_from_file(common_features_file_path)["features"] + + # Check is entered features contains in configuration file + features_diff = builder_features_list - common_features_list + + if !features_diff.empty? + raise "Unexpected features: " + features_diff.join(', ') + end + + # Generate JSON from feature names + feature_bodies = builder_features_list.map { |feature_name| { :name => feature_name, :enabled => true} } + features = { :features => features_body } + features_json = JSON.pretty_generate(features) + + unless File.exists? project_features_file_path + raise "Unable to load features from file at #{path}" + else + File.open(project_features_file_path, "w") do |f| + f.write(features_json) + end + end + + def self.get_features_from_file(path) + unless File.exists? path + raise "Unable to load features from file at #{path}" + else + YAML.load_file(path)["features"] + end + end + + private_class_method :new, :get_features_from_file + + end +end