require 'cocoapods' module ORM class CreateHelper ORM_PLUGIN_TEMPLATE_URL = "https://gitee.com/mvn/pod-template.git".freeze attr_reader :project_name attr_reader :class_prefix attr_reader :template_url def initialize(name, prefix = '', template_url = ORM_TEMPLATE_TAG_VERSION) @project_name = name @class_prefix = prefix @template_url = template_url end def setup(fast = false, skip= false) if fast then p '1111111=======' p Ormdev::SHUtil.run('ls -la') else end end # Clones the template from the remote in the working directory using # the name of the Pod. # # @return [void] # def clone_template Pod::UI.section("Cloning `#{template_repo_url}` into `#{@project_name}`.") do svn! ['checkout', template_repo_url, @project_name] end end # Runs the template configuration utilities. # # @return [void] # def setup string_replacements = { # "PROJECT_OWNER" => @configurator.user_name, "TODAYS_DATE" => Time.now.strftime("%m/%d/%Y"), "TODAYS_YEAR" => Time.now.year.to_s, "PROJECT" => @project_name, "OrmPro" => @class_prefix } Dir.glob(project_folder + "/**/**/**/**").each do |name| next if Dir.exists? name text = File.read(name) for find, replace in string_replacements text = text.gsub(find, replace) end File.open(name, "w") { |file| file.puts text } end # shared schemes have project specific names scheme_path = project_folder + "/PROJECT.xcodeproj/xcshareddata/xcschemes/" raise Pod::Informative, 'No Xcode project shared schemes found, please specify one' unless Dir.exists? scheme_path File.rename(scheme_path + "PROJECT.xcscheme", scheme_path + @project_name + ".xcscheme") # rename xcproject File.rename(project_folder + "/PROJECT.xcodeproj", File.join(project_folder, "#{@project_name}.xcodeproj")) # change app file prefixes ["OrmProAppDelegate.h", "OrmProAppDelegate.m"].each do |file| before = project_folder + "/PROJECT/" + file next unless File.exists? before after = project_folder + "/PROJECT/" + file.gsub("OrmPro", @class_prefix) File.rename before, after end safe_rename_file("#{project_folder}/PROJECTTests/PROJECTTests.m", "#{project_folder}/PROJECTTests/#{@project_name}Tests.m") safe_rename_file("#{project_folder}/PROJECTUITests/PROJECTUITests.m", "#{project_folder}/PROJECTUITests/#{@project_name}UITests.m") safe_rename_dir("#{project_folder}/PROJECT", "#{project_folder}/#{@project_name}") safe_rename_dir("#{project_folder}/PROJECTTests", "#{project_folder}/#{@project_name}Tests") safe_rename_dir("#{project_folder}/PROJECTUITests", "#{project_folder}/#{@project_name}UITests") reinitialize_svn_repo "#{@project_name}.xcodeproj" end # Runs the template configuration utilities. # # @return [void] # def print_info Pod::UI.puts "\nTo learn more about the template see `#{template_repo_url}`." end private #----------------------------------------# # !@group Private helpers extend Pod::Executable executable :svn def project_folder @project_name end def reinitialize_svn_repo `rm -rf .svn` end def safe_rename_dir(old, dir_name) if Dir.exist? old File.rename(old, dir_name) end end def safe_rename_file(old, file_name) if File.exist? old File.rename(old, file_name) end end # Checks if a template URL is given else returns the TEMPLATE_REPO URL # # @return String # def template_repo_url @template_url || ORM_TEMPLATE_TAG_URL end end end