From dbfc6153ab5a96761b1307f7fa163dc0d527ba87 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 18:17:39 +0300 Subject: [PATCH 01/21] Add uploadFeaturesToProject lane --- xcode/commonFastfile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 3886625..3d82867 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -106,6 +106,26 @@ 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 + 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 +end + private_lane :buildConfiguration do |options| appName = options[:appName] || $appName @@ -136,6 +156,10 @@ private_lane :buildConfiguration do |options| installDependencies(options) + if options[:features] + uploadFeaturesToProject(options) + end + if !(options[:uploadToFabric] || options[:uploadToAppStore]) options[:skip_package_ipa] = true @@ -397,6 +421,10 @@ 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' From aa00fe13cae04b488a331afeb1fa6017ac1245cf Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 19:55:10 +0300 Subject: [PATCH 02/21] Add Features class --- xcode/commonFastfile | 27 ++++-------- xcode/fastlane/touchlane/lib/touchlane.rb | 3 +- .../touchlane/lib/touchlane/features.rb | 41 +++++++++++++++++++ 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 xcode/fastlane/touchlane/lib/touchlane/features.rb 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 From a47f0b6218a864abfe5b10c094cbf516edc2dd47 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 20:00:22 +0300 Subject: [PATCH 03/21] Fix file type --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ac4eb16..3446ca5 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -110,7 +110,7 @@ private_lane lane :uploadFeaturesToProject do |options| app_target_folder_name = options[:appName] || $appName 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" + common_features_file_path = File.expand_path "../common/build_options/Features.yaml" builder_features_list = options[:features] # [ "Feature1", "Feature2", "Feature3" ] From 67418eefc35396544f3b5d69edd99ed215d69c9c Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 20:57:09 +0300 Subject: [PATCH 04/21] Code correction --- xcode/fastlane/touchlane/lib/touchlane/features.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 3c50022..3345c01 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -24,6 +24,7 @@ module Touchlane else File.open(project_features_file_path, "w") do |f| f.write(features_json) + end end end From 46be166a04fb5f83a431c9f675951b0598de7615 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 21:12:05 +0300 Subject: [PATCH 05/21] Code correction --- xcode/commonFastfile | 6 +++--- xcode/fastlane/touchlane/lib/touchlane/features.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 3446ca5..48b8c8a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -106,14 +106,14 @@ private_lane :addShield do |options| end end -private_lane lane :uploadFeaturesToProject do |options| +private_lane :uploadFeaturesToProject do |options| app_target_folder_name = options[:appName] || $appName 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.yaml" - builder_features_list = options[:features] # [ "Feature1", "Feature2", "Feature3" ] - + builder_features_list = options[:features].split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] + Touchlane::Features.generate_features_file_in_project(builder_features_list, common_features_file_path, project_features_file_path) end diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 3345c01..4806fba 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -16,7 +16,7 @@ module Touchlane # Generate JSON from feature names feature_bodies = builder_features_list.map { |feature_name| { :name => feature_name, :enabled => true} } - features = { :features => features_body } + features = { :features => feature_bodies } features_json = JSON.pretty_generate(features) unless File.exists? project_features_file_path @@ -32,7 +32,7 @@ module Touchlane unless File.exists? path raise "Unable to load features from file at #{path}" else - YAML.load_file(path)["features"] + YAML.load_file(path) end end From 136beef976eae2c184cdcda51338cbcb43ccdbbb Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 21:12:58 +0300 Subject: [PATCH 06/21] Fix typo --- xcode/fastlane/touchlane/lib/touchlane/features.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 4806fba..f0d55a7 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -20,7 +20,7 @@ module Touchlane features_json = JSON.pretty_generate(features) unless File.exists? project_features_file_path - raise "Unable to load features from file at #{path}" + raise "Unable to load features to file at #{path}" else File.open(project_features_file_path, "w") do |f| f.write(features_json) From 2712da9b8941b3bbef80f318e93cf5790a1695c5 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 12 Dec 2020 21:16:07 +0300 Subject: [PATCH 07/21] Code correction --- xcode/fastlane/touchlane/lib/touchlane/features.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index f0d55a7..00a4e3e 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -28,7 +28,7 @@ module Touchlane end end - def self.get_features_from_file(path) + def self.get_features_from_file(path) unless File.exists? path raise "Unable to load features from file at #{path}" else From a5f2b49a5126c35d19690f8c6030057d21bc571a Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 14 Dec 2020 11:58:58 +0300 Subject: [PATCH 08/21] Fix names filter --- xcode/commonFastfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 48b8c8a..4efcb84 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -112,7 +112,9 @@ private_lane :uploadFeaturesToProject do |options| 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.yaml" - builder_features_list = options[:features].split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] + builder_features_list = options[:features] + .split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] + .reject { |feature_name| feature_name.empty? } Touchlane::Features.generate_features_file_in_project(builder_features_list, common_features_file_path, project_features_file_path) end From b3751302a90e2dbc89b7a9b0ea603e2d845e2bda Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 14 Dec 2020 20:58:19 +0300 Subject: [PATCH 09/21] Add features generator --- .../features_generator/features_generator.rb | 55 +++++++++++++++++++ .../features_generator/features_generator.sh | 14 +++++ 2 files changed, 69 insertions(+) create mode 100755 xcode/build_phases/features_generator/features_generator.rb create mode 100755 xcode/build_phases/features_generator/features_generator.sh diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb new file mode 100755 index 0000000..c770014 --- /dev/null +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -0,0 +1,55 @@ +require 'yaml' +require 'erb' + +# Input files paths +build_settings_file_path = ARGV[0] +generated_features_enum_file_path = ARGV[1] + +features_enum_template = +" +//MARK: - Feature toggles + +public enum FeatureToggles: String, Codable, RawRepresentable, CaseIterable { + <% for @item in @items %> + case <%= @item %> + <% end %> +} +" + +class FeatureUtils + include ERB::Util + + attr_accessor :items + + def initialize(items) + @items = items + end + + def render(template) + ERB.new(template).result(binding) + end +end + +def save(path, data) + unless File.exists? path + raise "Unable to safe features to file at #{path}" + else + File.open(path, "w") do |f| + f.write(data) + end + end +end + +def get_features_from_file(path) + unless File.exists? path + raise "Unable to load features from file at #{path}" + else + YAML.load_file(path) + end +end + +build_settings_features_list = get_features_from_file(build_settings_file_path)["features"] +utils = FeatureUtils.new(build_settings_features_list) + +data = utils.render(features_enum_template).strip +save(generated_features_enum_file_path, data) diff --git a/xcode/build_phases/features_generator/features_generator.sh b/xcode/build_phases/features_generator/features_generator.sh new file mode 100755 index 0000000..2c8f94b --- /dev/null +++ b/xcode/build_phases/features_generator/features_generator.sh @@ -0,0 +1,14 @@ +readonly build_settings_file_path="${PROJECT_DIR}/common/build_settings.yaml" +readonly generated_file_path="${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift" + +if ! [ -e ${build_settings_file_path} ]; then + echo "File ${PROJECT_DIR}/common/build_settings.yaml does not exist. Add this file and try again." + exit 1 +fi + +if ! [ -e ${generated_file_path} ]; then + echo "File ${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift does not exist. Add this file and try again." + exit 1 +fi + +ruby ${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb ${build_settings_file_path} ${generated_file_path} From 1f321c27c97cb4d9c3268af67954d906f6ef2f4c Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 10:59:14 +0300 Subject: [PATCH 10/21] Add manager module and code correction --- .../features_generator/features_generator.rb | 37 ++++++------------- .../features_generator/features_generator.sh | 18 +++++---- xcode/commonFastfile | 8 ++-- .../touchlane/lib/touchlane/configuration.rb | 2 + .../touchlane/lib/touchlane/features.rb | 31 +++++----------- xcode/managers/lib/file_manager.rb | 27 ++++++++++++++ xcode/managers/managers.rb | 3 ++ 7 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 xcode/managers/lib/file_manager.rb create mode 100644 xcode/managers/managers.rb diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index c770014..e35bb41 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -1,6 +1,8 @@ require 'yaml' require 'erb' +require_relative 'managers/managers' + # Input files paths build_settings_file_path = ARGV[0] generated_features_enum_file_path = ARGV[1] @@ -9,9 +11,9 @@ features_enum_template = " //MARK: - Feature toggles -public enum FeatureToggles: String, Codable, RawRepresentable, CaseIterable { - <% for @item in @items %> - case <%= @item %> +public enum FeatureToggle: String, Codable, RawRepresentable, CaseIterable { + <% for @feature in @features %> + case <%= @feature %> <% end %> } " @@ -19,10 +21,10 @@ public enum FeatureToggles: String, Codable, RawRepresentable, CaseIterable { class FeatureUtils include ERB::Util - attr_accessor :items + attr_accessor :features - def initialize(items) - @items = items + def initialize(features) + @features = features end def render(template) @@ -30,26 +32,9 @@ class FeatureUtils end end -def save(path, data) - unless File.exists? path - raise "Unable to safe features to file at #{path}" - else - File.open(path, "w") do |f| - f.write(data) - end - end -end +build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] -def get_features_from_file(path) - unless File.exists? path - raise "Unable to load features from file at #{path}" - else - YAML.load_file(path) - end -end - -build_settings_features_list = get_features_from_file(build_settings_file_path)["features"] utils = FeatureUtils.new(build_settings_features_list) +rendered_enum = utils.render(features_enum_template).strip -data = utils.render(features_enum_template).strip -save(generated_features_enum_file_path, data) +Managers::FileManager.save_data_to_file(generated_features_enum_file_path, rendered_enum) diff --git a/xcode/build_phases/features_generator/features_generator.sh b/xcode/build_phases/features_generator/features_generator.sh index 2c8f94b..dbe7b22 100755 --- a/xcode/build_phases/features_generator/features_generator.sh +++ b/xcode/build_phases/features_generator/features_generator.sh @@ -1,14 +1,18 @@ -readonly build_settings_file_path="${PROJECT_DIR}/common/build_settings.yaml" -readonly generated_file_path="${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift" +# Input paths +readonly BUILD_SETTINGS_FILE_PATH=${1:-${PROJECT_DIR}/common/build_settings.yaml} +readonly FEATURES_ENUM_FILE_PATH=${2:-${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift} -if ! [ -e ${build_settings_file_path} ]; then - echo "File ${PROJECT_DIR}/common/build_settings.yaml does not exist. Add this file and try again." +# Features enunm generator script +readonly GENERATOR_SCRIPT=${${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb} + +if ! [ -e ${BUILD_SETTINGS_FILE_PATH} ]; then + echo "File ${BUILD_SETTINGS_FILE_PATH} does not exist. Add this file and try again." exit 1 fi -if ! [ -e ${generated_file_path} ]; then - echo "File ${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift does not exist. Add this file and try again." +if ! [ -e ${FEATURES_ENUM_FILE_PATH} ]; then + echo "File ${FEATURES_ENUM_FILE_PATH} does not exist. Add this file and try again." exit 1 fi -ruby ${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb ${build_settings_file_path} ${generated_file_path} +ruby ${GENERATOR_SCRIPT} ${BUILD_SETTINGS_FILE_PATH} ${FEATURES_ENUM_FILE_PATH} \ No newline at end of file diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 4efcb84..07f75da 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -106,17 +106,17 @@ private_lane :addShield do |options| end end -private_lane :uploadFeaturesToProject do |options| +private_lane :generateFeaturesJSONFile do |options| app_target_folder_name = options[:appName] || $appName 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.yaml" + 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" ] .reject { |feature_name| feature_name.empty? } - Touchlane::Features.generate_features_file_in_project(builder_features_list, common_features_file_path, project_features_file_path) + Touchlane::Features.generate_features_file_in_project(builder_features_list, build_settings_file_path, project_features_file_path) end private_lane :buildConfiguration do |options| @@ -149,7 +149,7 @@ private_lane :buildConfiguration do |options| installDependencies(options) - if options[:features] + unless options[:features].nil? uploadFeaturesToProject(options) end diff --git a/xcode/fastlane/touchlane/lib/touchlane/configuration.rb b/xcode/fastlane/touchlane/lib/touchlane/configuration.rb index 02cc4d3..00b93a1 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/configuration.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/configuration.rb @@ -1,5 +1,7 @@ require "yaml" +require_relative 'managers/managers' + module Touchlane class Configuration def initialize(type, app_identifier, apple_id, team_id, itc_team_id) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 00a4e3e..0173dc4 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -1,14 +1,15 @@ require 'json' -require 'yaml' + +require_relative 'managers/managers' 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"] + def self.generate_features_file_in_project(builder_features_list, build_settings_file_path, project_features_file_path) + build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] # Check is entered features contains in configuration file - features_diff = builder_features_list - common_features_list + features_diff = builder_features_list - build_settings_features_list if !features_diff.empty? raise "Unexpected features: " + features_diff.join(', ') @@ -16,27 +17,13 @@ module Touchlane # Generate JSON from feature names feature_bodies = builder_features_list.map { |feature_name| { :name => feature_name, :enabled => true} } - features = { :features => feature_bodies } - features_json = JSON.pretty_generate(features) + features_full_body = { :features => feature_bodies } + features_json = JSON.pretty_generate(features_full_body) - unless File.exists? project_features_file_path - raise "Unable to load features to file at #{path}" - else - File.open(project_features_file_path, "w") do |f| - f.write(features_json) - end - end + Managers::FileManager.save_data_to_file(project_features_file_path, features_json) 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) - end - end - - private_class_method :new, :get_features_from_file + private_class_method :new end end diff --git a/xcode/managers/lib/file_manager.rb b/xcode/managers/lib/file_manager.rb new file mode 100644 index 0000000..72381f5 --- /dev/null +++ b/xcode/managers/lib/file_manager.rb @@ -0,0 +1,27 @@ +require 'yaml' + +module Managers + class FileManager + + def self.save_data_to_file(path, data) + unless File.exists? path + raise "Unable to save data to file at #{path}" + else + File.open(path, "w") do |f| + f.write(data) + end + end + end + + def self.load_from_file_YAML(path) + unless File.exists? path + raise "Unable to load data from file at #{path}" + else + YAML.load_file(path) + end + end + + private_class_method :new + + end +end diff --git a/xcode/managers/managers.rb b/xcode/managers/managers.rb new file mode 100644 index 0000000..81e6279 --- /dev/null +++ b/xcode/managers/managers.rb @@ -0,0 +1,3 @@ +module Managers + require_relative "lib/file_manager" +end From e7574decbc69dd7b9be5fd35aa18caa3c8ed92c1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 11:05:35 +0300 Subject: [PATCH 11/21] Add check for nil --- xcode/build_phases/features_generator/features_generator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index e35bb41..925967e 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -34,6 +34,10 @@ end build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] +if build_settings_features_list.nil? or build_settings_features_list.empty? + raise "There are no features in " + build_settings_file_path +end + utils = FeatureUtils.new(build_settings_features_list) rendered_enum = utils.render(features_enum_template).strip From 4564ffbd99208ded644b7ae8057e6314da4cd875 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 11:06:23 +0300 Subject: [PATCH 12/21] Add comment --- xcode/build_phases/features_generator/features_generator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index 925967e..07cb358 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -38,6 +38,7 @@ if build_settings_features_list.nil? or build_settings_features_list.empty? raise "There are no features in " + build_settings_file_path end +# Generate enum Feature Toggles utils = FeatureUtils.new(build_settings_features_list) rendered_enum = utils.render(features_enum_template).strip From 149a4d2dcb91a780c9c72fb1599e0551079e3991 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 11:23:15 +0300 Subject: [PATCH 13/21] Code correction --- xcode/build_phases/features_generator/features_generator.rb | 2 +- xcode/build_phases/features_generator/features_generator.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index 07cb358..d8a8f8e 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -1,7 +1,7 @@ require 'yaml' require 'erb' -require_relative 'managers/managers' +require_relative File.expand_path "build-scripts/xcode/managers/managers" # Input files paths build_settings_file_path = ARGV[0] diff --git a/xcode/build_phases/features_generator/features_generator.sh b/xcode/build_phases/features_generator/features_generator.sh index dbe7b22..730c2a2 100755 --- a/xcode/build_phases/features_generator/features_generator.sh +++ b/xcode/build_phases/features_generator/features_generator.sh @@ -3,7 +3,7 @@ readonly BUILD_SETTINGS_FILE_PATH=${1:-${PROJECT_DIR}/common/build_settings.yaml readonly FEATURES_ENUM_FILE_PATH=${2:-${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift} # Features enunm generator script -readonly GENERATOR_SCRIPT=${${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb} +readonly GENERATOR_SCRIPT=${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb if ! [ -e ${BUILD_SETTINGS_FILE_PATH} ]; then echo "File ${BUILD_SETTINGS_FILE_PATH} does not exist. Add this file and try again." From d7a571400d2fb819fa3c950174238b24d6a7a4ed Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 11:40:16 +0300 Subject: [PATCH 14/21] Code correction --- xcode/commonFastfile | 6 +++--- xcode/fastlane/touchlane/lib/touchlane/configuration.rb | 2 -- xcode/fastlane/touchlane/lib/touchlane/features.rb | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 07f75da..e36fee4 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -106,10 +106,10 @@ private_lane :addShield do |options| end end -private_lane :generateFeaturesJSONFile do |options| +private_lane :generateFeaturesFile do |options| app_target_folder_name = options[:appName] || $appName - project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features.json" + project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features/Features.json" build_settings_file_path = File.expand_path "../common/build_settings.yaml" builder_features_list = options[:features] @@ -150,7 +150,7 @@ private_lane :buildConfiguration do |options| installDependencies(options) unless options[:features].nil? - uploadFeaturesToProject(options) + generateFeaturesFile(options) end if !(options[:uploadToFabric] || options[:uploadToAppStore]) diff --git a/xcode/fastlane/touchlane/lib/touchlane/configuration.rb b/xcode/fastlane/touchlane/lib/touchlane/configuration.rb index 00b93a1..02cc4d3 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/configuration.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/configuration.rb @@ -1,7 +1,5 @@ require "yaml" -require_relative 'managers/managers' - module Touchlane class Configuration def initialize(type, app_identifier, apple_id, team_id, itc_team_id) diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 0173dc4..62d1b10 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -1,6 +1,6 @@ require 'json' -require_relative 'managers/managers' +require_relative File.expand_path "../build-scripts/xcode/managers/managers" module Touchlane class Features From 31cc96b6c66f50941e1c9c0f1bca6f02b810f44f Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 11:52:09 +0300 Subject: [PATCH 15/21] Fix enum path --- xcode/build_phases/features_generator/features_generator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/build_phases/features_generator/features_generator.sh b/xcode/build_phases/features_generator/features_generator.sh index 730c2a2..4e39fff 100755 --- a/xcode/build_phases/features_generator/features_generator.sh +++ b/xcode/build_phases/features_generator/features_generator.sh @@ -1,6 +1,6 @@ # Input paths readonly BUILD_SETTINGS_FILE_PATH=${1:-${PROJECT_DIR}/common/build_settings.yaml} -readonly FEATURES_ENUM_FILE_PATH=${2:-${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggles.swift} +readonly FEATURES_ENUM_FILE_PATH=${2:-${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggle.swift} # Features enunm generator script readonly GENERATOR_SCRIPT=${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb From 64c8f852989cdcef794866267d845adc676b720a Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 15:53:37 +0300 Subject: [PATCH 16/21] Fix PR --- xcode/commonFastfile | 8 ++++++-- .../fastlane/touchlane/lib/touchlane/features.rb | 15 ++++----------- xcode/managers/lib/file_manager.rb | 6 ++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index e36fee4..21fc50e 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -1,6 +1,7 @@ $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') require_relative 'fastlane/touchlane/lib/touchlane' +require_relative File.expand_path "../build-scripts/xcode/managers/managers" # ugly hack to add support for custom storage @@ -114,9 +115,12 @@ private_lane :generateFeaturesFile do |options| builder_features_list = options[:features] .split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] - .reject { |feature_name| feature_name.empty? } - Touchlane::Features.generate_features_file_in_project(builder_features_list, build_settings_file_path, project_features_file_path) + build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] + + features_hash = Touchlane::Features.generate_features_hash(builder_features_list, build_settings_features_list) + + Managers::FileManager.save_data_to_file_in_json(project_features_file_path, features_hash) end private_lane :buildConfiguration do |options| diff --git a/xcode/fastlane/touchlane/lib/touchlane/features.rb b/xcode/fastlane/touchlane/lib/touchlane/features.rb index 62d1b10..e6e65c5 100644 --- a/xcode/fastlane/touchlane/lib/touchlane/features.rb +++ b/xcode/fastlane/touchlane/lib/touchlane/features.rb @@ -1,12 +1,7 @@ -require 'json' - -require_relative File.expand_path "../build-scripts/xcode/managers/managers" - module Touchlane class Features - def self.generate_features_file_in_project(builder_features_list, build_settings_file_path, project_features_file_path) - build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] + def self.generate_features_hash(builder_features_list, build_settings_features_list) # Check is entered features contains in configuration file features_diff = builder_features_list - build_settings_features_list @@ -15,12 +10,10 @@ module Touchlane 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} } + # Generate hash from feature names + feature_bodies = builder_features_list.map { |feature_name| { :name => feature_name, :enabled => true } } features_full_body = { :features => feature_bodies } - features_json = JSON.pretty_generate(features_full_body) - - Managers::FileManager.save_data_to_file(project_features_file_path, features_json) + features_full_body.to_hash() end private_class_method :new diff --git a/xcode/managers/lib/file_manager.rb b/xcode/managers/lib/file_manager.rb index 72381f5..45bdda8 100644 --- a/xcode/managers/lib/file_manager.rb +++ b/xcode/managers/lib/file_manager.rb @@ -1,4 +1,5 @@ require 'yaml' +require 'json' module Managers class FileManager @@ -20,6 +21,11 @@ module Managers YAML.load_file(path) end end + + def self.save_data_to_file_in_json(path, data) + json_data = JSON.pretty_generate(data) + save_data_to_file(path, json_data) + end private_class_method :new From 545f8d4c2f115f3335e6c7006a3a8398a567ba3b Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 15 Dec 2020 18:27:25 +0300 Subject: [PATCH 17/21] Fix PR --- xcode/commonFastfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 21fc50e..2bcb73a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -107,22 +107,6 @@ private_lane :addShield do |options| end end -private_lane :generateFeaturesFile do |options| - app_target_folder_name = options[:appName] || $appName - - project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features/Features.json" - 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" ] - - build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] - - features_hash = Touchlane::Features.generate_features_hash(builder_features_list, build_settings_features_list) - - Managers::FileManager.save_data_to_file_in_json(project_features_file_path, features_hash) -end - private_lane :buildConfiguration do |options| appName = options[:appName] || $appName @@ -418,6 +402,22 @@ 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 generateFeaturesFile(options) + app_target_folder_name = options[:appName] || $appName + + project_features_file_path = File.expand_path "../#{app_target_folder_name}/Resources/Features/Features.json" + 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" ] + + build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] + + features_hash = Touchlane::Features.generate_features_hash(builder_features_list, build_settings_features_list) + + Managers::FileManager.save_data_to_file_in_json(project_features_file_path, features_hash) +end + def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) require 'xcodeproj' From 4777c0c5977783867282157371f304df8e8920b1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 18 Dec 2020 17:55:27 +0300 Subject: [PATCH 18/21] Fix PR --- xcode/build_phases/features_generator/features_generator.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xcode/build_phases/features_generator/features_generator.sh b/xcode/build_phases/features_generator/features_generator.sh index 4e39fff..b41cb44 100755 --- a/xcode/build_phases/features_generator/features_generator.sh +++ b/xcode/build_phases/features_generator/features_generator.sh @@ -3,7 +3,8 @@ readonly BUILD_SETTINGS_FILE_PATH=${1:-${PROJECT_DIR}/common/build_settings.yaml readonly FEATURES_ENUM_FILE_PATH=${2:-${PROJECT_DIR}/${PRODUCT_NAME}/Resources/Features/FeatureToggle.swift} # Features enunm generator script -readonly GENERATOR_SCRIPT=${PROJECT_DIR}/build-scripts/xcode/build_phases/features_generator/features_generator.rb +readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +readonly GENERATOR_SCRIPT=${CURRENT_DIR}/features_generator.rb if ! [ -e ${BUILD_SETTINGS_FILE_PATH} ]; then echo "File ${BUILD_SETTINGS_FILE_PATH} does not exist. Add this file and try again." From 1a344aeed7b058f3278616627392b77bf7116701 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 18 Dec 2020 18:03:04 +0300 Subject: [PATCH 19/21] Fix PR --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 2bcb73a..f6fbb5a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -1,7 +1,7 @@ $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') require_relative 'fastlane/touchlane/lib/touchlane' -require_relative File.expand_path "../build-scripts/xcode/managers/managers" +require_relative 'managers/managers' # ugly hack to add support for custom storage From 7b5ba18dfa7cbf1570c203fad73a4237828a5550 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 18 Dec 2020 18:29:28 +0300 Subject: [PATCH 20/21] Fix PR --- xcode/build_phases/features_generator/features_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index d8a8f8e..834500b 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -1,7 +1,7 @@ require 'yaml' require 'erb' -require_relative File.expand_path "build-scripts/xcode/managers/managers" +require_relative "../../managers/managers" # Input files paths build_settings_file_path = ARGV[0] From 688a82854863d3aba0ffed2cb6a7afc4ee7d1814 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 18 Dec 2020 18:30:19 +0300 Subject: [PATCH 21/21] Fix PR --- xcode/build_phases/features_generator/features_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/build_phases/features_generator/features_generator.rb b/xcode/build_phases/features_generator/features_generator.rb index 834500b..6601ba6 100755 --- a/xcode/build_phases/features_generator/features_generator.rb +++ b/xcode/build_phases/features_generator/features_generator.rb @@ -1,7 +1,7 @@ require 'yaml' require 'erb' -require_relative "../../managers/managers" +require_relative '../../managers/managers' # Input files paths build_settings_file_path = ARGV[0]