Add features generator
This commit is contained in:
parent
a5f2b49a51
commit
b3751302a9
|
|
@ -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)
|
||||
|
|
@ -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}
|
||||
Loading…
Reference in New Issue