Class: Stool::Command::WorkSpace::Update

Inherits:
Stool::Command::WorkSpace show all
Includes:
ArrayUtile
Defined in:
lib/stool/Command/WorkSpace/update.rb

Instance Attribute Summary

Attributes inherited from Stool::Command::WorkSpace

#info, #tag

Instance Method Summary collapse

Methods included from ArrayUtile

#diffOf

Methods inherited from Stool::Command::WorkSpace

#cleanAllCache, #existAtConfig?, #getAllRepos, #hasPodfile?, #pathForTaskInfo_last_pod_update

Methods inherited from Stool::Command

#checkConfigFile, options, #pp

Constructor Details

#initialize(argv) ⇒ Update

Returns a new instance of Update.



16
17
18
19
# File 'lib/stool/Command/WorkSpace/update.rb', line 16

def initialize(argv)
  @tag = argv.shift_argument
  super
end

Instance Method Details

#check_lastUpdateObject

检测上一次更新用到的lib,源码是否与本次有冲突



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/stool/Command/WorkSpace/update.rb', line 84

def check_lastUpdate
  lastTaskInfo = TaskInfo::fromYAML(pathForTaskInfo_last_pod_update)
  unless lastTaskInfo
    cleanAllCache
    return
  end

  if lastTaskInfo.allUseCode != @info.allUseCode
    cleanAllCache
    return
  end

  diff = diffOf(lastTaskInfo.otherCode,@info.otherCode)
  diff.each do |x|
    if x.length > 0
      puts "--- 清除lib缓存:#{x} ..."
      puts `pod cache clean #{x} --all`
    end
  end

end

#del_folersObject

删除一些相关文件



71
72
73
74
75
76
77
78
79
80
# File 'lib/stool/Command/WorkSpace/update.rb', line 71

def del_folers
  Dir.chdir(@info.path)
  # Dir.rmdir(File.join(@info.path, 'Pods'))
  puts `rm -rf Pods/`

  podLock = File.join(@info.path,"Podfile.lock")
  if File.exist?(podLock)
    File.delete(podLock)
  end
end

#localLibs_git_upObject

更新项目用到的所有本地库



59
60
61
62
63
64
65
66
67
68
# File 'lib/stool/Command/WorkSpace/update.rb', line 59

def localLibs_git_up
  @@config.pools.map do |pool|
    @info.localLibs.map do |lib|
      libInfo = pool.searchLib(lib)
      if libInfo
        libInfo.gitUp
      end
    end
  end
end

#pod_updateObject

执行pod update



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/stool/Command/WorkSpace/update.rb', line 107

def pod_update
  useCode = @info.localLibs + @info.otherCode
  useCode = useCode.uniq
  useCode.collect! {|item|
    item + "_use_code=1 "
  }
  puts useCode
  libs_useCode = useCode.join
  if @info.allUseCode
    libs_useCode = 'use_code=1' + libs_useCode
  end

  @info.doCacheByYAML(pathForTaskInfo_last_pod_update)

  puts "---源码库有" + libs_useCode
  Dir.chdir(@info.path)
  puts '---当前目录' + Dir.getwd
  puts "---update中...."
  puts `#{libs_useCode} pod update --no-repo-update`
end

#repos_upObject

更新相关repo(除了master)



49
50
51
52
53
54
55
56
# File 'lib/stool/Command/WorkSpace/update.rb', line 49

def repos_up
  getAllRepos.each do |repo|
    puts "*** begin update repo <#{repo}>"
    `pod repo update #{repo}`
    puts "*** end update repo"
    puts ''
  end
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stool/Command/WorkSpace/update.rb', line 36

def run
  repos_up
  localLibs_git_up
  @info.task_git_up
  @info.edit_podfile_use_loaclLibs
  del_folers
  check_lastUpdate
  pod_update
  @info.resetPofile
  @info.open_task
end

#validate!Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stool/Command/WorkSpace/update.rb', line 21

def validate!
  unless @tag
    help! 'need the tag of workspace you configed.'
  end
  unless existAtConfig?
    help! "To run, please ensure the tag(#{@tag}) exist."
  end
  unless hasPodfile?(@info.path)
    help! 'To run, please ensure the workspace contain a podfile in zhe folder.' + "#{@info.path}"
  end
  super
end