class Fastlane::Sync::SyncMain
Public Class Methods
run(params,available_options)
click to toggle source
# File lib/fastlane/plugin/rocket/sync/sync_main.rb, line 17 def self.run(params,available_options) Tools.formatLog(params,available_options); git = ENV["R_SYNC_GIT"] branch = ENV["R_SYNC_BRANCH"] Tools.title("拉取壳工程仓库") Tools.log("缓存地址 => #{SYNC_PATH}") Tools.clone(git,branch,MAIN_XCODEPROJ_PATH,false) Tools.title("同步壳工程") #获取壳工程commit commit = Tools.return_shell("cd #{MAIN_XCODEPROJ_PATH}&&git rev-parse --short HEAD") #当前脚本执行地址 pwd_path = Tools.return_shell("pwd") #当前项目的.gitignore gitignore_path = "#{pwd_path}/.gitignore" #独立运行文件名 example = "rocketExample" #独立运行地址 example_path = "#{pwd_path}/#{example}" #可自定义podfile文件 yml_path = "#{example_path}/Podfile.yml" #壳工程的Pods文件夹 pods_path = "#{example_path}/Pods" #壳工程的.git文件夹 example_git_path = "#{example_path}/.git" #壳工程的.gitlab文件夹 example_gitlab_path = "#{example_path}/.gitlab" #壳工程的.arcconfig文件 example_arcconfig_path = "#{example_path}/.arcconfig" #壳工程的.gitignore文件 example_gitignore_path = "#{example_path}/.gitignore" #壳工程信息 写入Podfile.local str = "#壳工程分支:#{branch} 壳工程commit:#{commit}" shell_str = "echo '#{str}' >> #{yml_path}" unless File.directory?(example_path) Tools.shell("mkdir -p #{example_path}") end unless FileTest::exist?(yml_path) Tools.shell(shell_str) else note = Tools.return_shell("fgrep '#壳工程分支' '#{yml_path}'") if note == -1 textAll = File.read(yml_path) textAll = str + "\n" + textAll f = open("#{yml_path}","w") f.puts(textAll) f.close else Tools.shell("sed -i '' \"s/#{note}/#{str}/g\" '#{yml_path}'") end end #设置yml_path # pwd_path = "/Users/leo/Documents/code/iOS/BCLaunchModule" podspecs = Dir.glob("#{pwd_path}/*.podspec") podspecs.each do |podspec| pod_name = File.basename(podspec,".podspec") pod_import = "pod '#{pod_name}' ,:path => '../'" note = Tools.return_shell("fgrep \"'#{pod_name}'\" '#{yml_path}'") if note == -1 f = open("#{yml_path}","a") f.puts("#{pod_import}") f.close end end #删除文件 Tools.deleteDirPath(example_path,[yml_path,pods_path],example_path) #将壳工程文件copy到独立运行地址 FileUtils.copy_entry(MAIN_XCODEPROJ_PATH,example_path) #清理.git等 Tools.deleteDirPath(example_git_path) Tools.deleteDirPath(example_gitlab_path) Tools.deleteDirPath(example_arcconfig_path) Tools.deleteDirPath(example_gitignore_path) #设置当前项目的.gitignore文件 忽略example note = Tools.return_shell("fgrep '#{example}' '#{gitignore_path}'") if note == -1 f = open("#{gitignore_path}","a") f.puts("\n#{example}/*\n!#{example}/Podfile.yml") f.close end end