require 'ios/module/setup/MessageBank' require 'ios/module/setup/ConfigureSwift' require 'ios/module/setup/TuistCommands' require 'colored2' require 'fileutils' module IOS class TemplateConfigurator attr_reader :pod_name, :pods_for_podfile, :prefixes, :project_filename, :template_path, :tuist_commands def initialize() @pod_name = "" @project_filename = "Shell.xcworkspace" @pods_for_podfile = [] @prefixes = [] dir = App.gem_path @template_path = File.join(dir, "lib/ios/module/templates") @message_bank = MessageBank.new(self) @tuist_commands = TuistCommands.new end def printMessage(message) puts "" puts "==> " + message end def printDone puts "\n✅ " + "DONE".green end def ask(question) answer = "" loop do puts "\n#{question}" @message_bank.show_prompt answer = STDIN.gets.chomp break if answer.length > 0 print "\nInforme uma resposta" end answer end def ask_with_answers(question, possible_answers) print "\n#{question}? [" print_info = Proc.new { possible_answers_string = possible_answers.each_with_index do |answer, i| _answer = (i == 0) ? answer.underlined : answer print " " + _answer print(" /") if i != possible_answers.length - 1 end print " ]\n" } print_info.call answer = "" loop do @message_bank.show_prompt answer = STDIN.gets.downcase.chomp answer = "yes" if answer == "y" answer = "no" if answer == "n" # default to first answer if answer == "" answer = possible_answers[0].downcase print answer.yellow end break if possible_answers.map { |a| a.downcase }.include? answer print "\nRespostas possíveis [" print_info.call end answer end def run raise "Para rodar a rotina, você deve estar na raiz do projeto" if not File.exists?(@project_filename) @pod_name = ask("Qual o nome do módulo?") ConfigureSwift.perform(configurator: self) run_swiftgen run_tuist_generate @message_bank.done_message end def user_name (ENV['GIT_COMMITTER_NAME'] || github_user_name || `git config user.name` || ``).strip end def user_email (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip end def github_user_name github_user_name = `security find-internet-password -s github.com | grep acct | sed 's/"acct"="//g' | sed 's/"//g'`.strip is_valid = github_user_name.empty? or github_user_name.include? '@' return is_valid ? nil : github_user_name end def run_tuist_generate if Dir.exists? "Example" Dir.chdir "Example" do @tuist_commands.generateExample(false) printDone end end end def run_swiftgen if File.exists? "swiftgen.yml" printMessage("Rodando " + "swiftgen".magenta + " no módulo") @message_bank.run_command "swiftgen" printDone end end end end