Merge pull request #237 from TouchInstinct/feature/feature_toggles
Add generateFeaturesFile lane and feature generator
This commit is contained in:
commit
7a91383726
|
|
@ -0,0 +1,45 @@
|
|||
require 'yaml'
|
||||
require 'erb'
|
||||
|
||||
require_relative '../../managers/managers'
|
||||
|
||||
# Input files paths
|
||||
build_settings_file_path = ARGV[0]
|
||||
generated_features_enum_file_path = ARGV[1]
|
||||
|
||||
features_enum_template =
|
||||
"
|
||||
//MARK: - Feature toggles
|
||||
|
||||
public enum FeatureToggle: String, Codable, RawRepresentable, CaseIterable {
|
||||
<% for @feature in @features %>
|
||||
case <%= @feature %>
|
||||
<% end %>
|
||||
}
|
||||
"
|
||||
|
||||
class FeatureUtils
|
||||
include ERB::Util
|
||||
|
||||
attr_accessor :features
|
||||
|
||||
def initialize(features)
|
||||
@features = features
|
||||
end
|
||||
|
||||
def render(template)
|
||||
ERB.new(template).result(binding)
|
||||
end
|
||||
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
|
||||
|
||||
# Generate enum Feature Toggles
|
||||
utils = FeatureUtils.new(build_settings_features_list)
|
||||
rendered_enum = utils.render(features_enum_template).strip
|
||||
|
||||
Managers::FileManager.save_data_to_file(generated_features_enum_file_path, rendered_enum)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# 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/FeatureToggle.swift}
|
||||
|
||||
# Features enunm generator script
|
||||
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."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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 ${GENERATOR_SCRIPT} ${BUILD_SETTINGS_FILE_PATH} ${FEATURES_ENUM_FILE_PATH}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
$appName = File.basename(Dir['../*.xcworkspace'].first, '.*')
|
||||
|
||||
require_relative 'fastlane/touchlane/lib/touchlane'
|
||||
require_relative 'managers/managers'
|
||||
|
||||
# ugly hack to add support for custom storage
|
||||
|
||||
|
|
@ -136,6 +137,10 @@ private_lane :buildConfiguration do |options|
|
|||
|
||||
installDependencies(options)
|
||||
|
||||
unless options[:features].nil?
|
||||
generateFeaturesFile(options)
|
||||
end
|
||||
|
||||
if !(options[:uploadToFabric] || options[:uploadToAppStore])
|
||||
options[:skip_package_ipa] = true
|
||||
|
||||
|
|
@ -397,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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
module Touchlane
|
||||
class 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
|
||||
|
||||
if !features_diff.empty?
|
||||
raise "Unexpected features: " + features_diff.join(', ')
|
||||
end
|
||||
|
||||
# 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_full_body.to_hash()
|
||||
end
|
||||
|
||||
private_class_method :new
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
require 'yaml'
|
||||
require 'json'
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module Managers
|
||||
require_relative "lib/file_manager"
|
||||
end
|
||||
Loading…
Reference in New Issue