Class: PodfileTools

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-mPaaS/podfileTools.rb

Class Method Summary collapse

Class Method Details

.writeVersionCode(podfile_path) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
# File 'lib/cocoapods-mPaaS/podfileTools.rb', line 2

def self.writeVersionCode(podfile_path)
  baseline = BaselineTools.getBaselineMatched(podfile_path)
  version_code = BaselineTools.getVersionCodeInLocalByBaseline(baseline)
  # LogTools.p_red version_code.to_s

  # 先简单文本处理,todo ruby解析或者正则
  io = File::open(podfile_path).readlines

  # 全局判断不用了
  # io_full = File.read(podfile_path)

  override = File.new(podfile_path, "w")

  need_write_in_last = true

  # 先判断全局有没有
  # if !io_full.include?("mPaaS_version_code")
  #   need_write_in_last = true
  # end

  io.each do |line|
    if line.include?("mPaaS_version_code")
      next
    end

    override.puts line

    # 有 mPaaS_baseline 就写在下一行
    if line.include?("mPaaS_baseline")
      need_write_in_last = false
      override.puts("mPaaS_version_code #{version_code}   # This line is maintained by MPaaS plugin automatically. Please don't modify.")

      LogTools.p "write 'mPaaS_version_code #{version_code}' in the Podfile"
    end
  end

  # 如果上面 mPaaS_baseline 没加过,就写在最后
  if need_write_in_last
    override.puts("")
    override.puts("mPaaS_version_code #{version_code}   # This line is maintained by MPaaS plugin automatically. Please don't modify.")

    LogTools.p "write 'mPaaS_version_code #{version_code}' in the Podfile"
  end

  override.close
end