Add manager module and code correction
This commit is contained in:
parent
b3751302a9
commit
1f321c27c9
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module Managers
|
||||
require_relative "lib/file_manager"
|
||||
end
|
||||
Loading…
Reference in New Issue