Class: Fastlane::Sync::SyncMain

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/rocket/sync/sync_main.rb

Class Method Summary collapse

Class Method Details

.run(params, available_options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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