require 'colored' require 'fileutils' require 'psych' require 'thor/actions' require_relative 'setup/TemplateConfigurator' require 'yk_command/config/yk_config' require 'pathname' module YkCommand PROJECT_CONFIG_FILE = '.YKProjectConfig.yml'.freeze class YkProject < Thor include Thor::Actions def initialize(args = [], options = {}, config = {}) super end no_commands do def prepare_project(pod_name, framework, prefix, author, at_path) des_path = Pathname.new(at_path) current_class_path = Pathname.new(File.dirname(File.expand_path __FILE__)) FileUtils.remove_dir("#{current_class_path.to_s + '/temp'}", true) FileUtils.copy_entry "#{current_class_path.to_s + '/YKProjectTemplate'}", "#{current_class_path.to_s + '/temp'}" prepare_template(YkConfig.new(at_path).read_config PROJECT_CONFIG_FILE) Pod::TemplateConfigurator.new(pod_name, framework, prefix, author, "#{current_class_path.to_s + '/temp'}").run #move temp folder to destination FileUtils.copy_entry "#{current_class_path.to_s + '/temp'}", "#{des_path.to_s + "/#{pod_name}"}" #删除临时目录 FileUtils.remove_dir("#{current_class_path.to_s + '/temp'}", true) end def prepare_template(config) current_class_path = Pathname.new(File.dirname(File.expand_path __FILE__)) temlates = ['ios', 'swift', 'macos-swift'] temlates.each do |folder| podfile = "#{current_class_path.to_s + '/temp/templates/' + folder + '/Example/Podfile'}" config['source'].each do |source| file_prepend podfile, source + "\n" end end end def file_prepend(file, str) new_contents = "" File.open(file, 'r') do |fd| contents = fd.read new_contents = str << contents end # Overwrite file but now with prepended string on it File.open(file, 'w') do |fd| fd.write(new_contents) end end # def read_config(at_path) # hostA = 'yeah' # hostB = 'ka' # config_repo_url = "http://gitlab.#{hostA}#{hostB}.com/App/iOS/YKComponents/com-manage-platform-resources/configruation-files.git" # system("git clone #{config_repo_url} #{at_path+'/configruation-files'}") # # config_file_path = "#{at_path}/#{PROJECT_CONFIG_FILE}" # FileUtils.copy_file "#{at_path+'/configruation-files/'+PROJECT_CONFIG_FILE}", config_file_path # FileUtils.remove_dir("#{at_path+'/configruation-files'}", true) # # File.exist?(config_file_path) ? YAML.load_file(config_file_path) : {} # end end end end