Class: ActionHandler
- Inherits:
-
Object
- Object
- ActionHandler
- Defined in:
- lib/sjpush.rb
Overview
require “sjpush/version” !/usr/bin/env ruby
Class Method Summary collapse
-
.getCurBranch ⇒ Object
获取当前的分支.
- .getPodspec ⇒ Object
- .getPodspecName ⇒ Object
- .getPodspecVersion ⇒ Object
- .searchPodspec ⇒ Object
- .updatePodspecVerAction ⇒ Object
Instance Method Summary collapse
-
#addCommand(order) ⇒ Object
-
Actions -.
-
- #addNewTagAction ⇒ Object
- #addNewTagForPodspecVersionAction ⇒ Object
- #commitAction ⇒ Object
- #deleteTagAction ⇒ Object
-
#directReleaseAction ⇒ Object
一键发布.
- #executeCommands ⇒ Object
- #getCocoapodsRepo ⇒ Object
- #getSubmitInfo ⇒ Object
- #handleSeq(seq) ⇒ Object
-
#initialize ⇒ ActionHandler
constructor
A new instance of ActionHandler.
- #nextCommand(beforeSeq) ⇒ Object
- #podReleaseAction ⇒ Object
- #pushAction ⇒ Object
Constructor Details
#initialize ⇒ ActionHandler
Returns a new instance of ActionHandler.
80 81 82 |
# File 'lib/sjpush.rb', line 80 def initialize() @commands = String.new end |
Class Method Details
.getCurBranch ⇒ Object
获取当前的分支
8 9 10 11 12 |
# File 'lib/sjpush.rb', line 8 def getCurBranch() # strip! 删除开头和末尾的空白字符 commands = IO.readlines(".git/HEAD").first.strip!; commands.sub!(/ref: refs\/heads\//, "") end |
.getPodspec ⇒ Object
16 17 18 |
# File 'lib/sjpush.rb', line 16 def getPodspec() Dir["*.podspec"].last end |
.getPodspecName ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sjpush.rb', line 65 def getPodspecName() s = searchPodspec() File.new(s, "r").each_line do |line| regex = "s.name(?:[^']+)'([^']+)'*" if /#{regex}/ =~ line @name = $1 break end end return @name end |
.getPodspecVersion ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sjpush.rb', line 51 def getPodspecVersion() s = searchPodspec() File.new(s, "r").each_line do |line| regex = "s.version(?:[^']+)'([^']+)'*" if /#{regex}/ =~ line @version = $1.to_i break end end return @version end |
.searchPodspec ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/sjpush.rb', line 20 def searchPodspec() s = ActionHandler.getPodspec() if s.nil? puts "\n已退出, 未搜索到 podspec 文件" exit end return s end |
.updatePodspecVerAction ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sjpush.rb', line 30 def updatePodspecVerAction() s = searchPodspec() contents = String.new File.new(s, "r").each_line do |line| regex = "s.version([^']+)'([^']+)'*" if /#{regex}/ =~ line v = ($2.to_i + 1).to_s regex = "'[^']+'" line = line.sub!(/#{regex}/, "'#{v}'") end contents += line end file = File.new(s, "w") file.syswrite(contents) file.close puts "\npodspec 版本已更新" end |
Instance Method Details
#addCommand(order) ⇒ Object
-
Actions -
102 103 104 105 106 107 108 |
# File 'lib/sjpush.rb', line 102 def addCommand(order) if @commands.length == 0 @commands << order else @commands << " && #{order}" end end |
#addNewTagAction ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/sjpush.rb', line 120 def addNewTagAction() puts "\n请输入新的标签:" newTag = gets.strip! submit = getSubmitInfo() addCommand "git tag -a '#{newTag}' -m '#{submit}'" addCommand "git push origin #{newTag}" end |
#addNewTagForPodspecVersionAction ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/sjpush.rb', line 129 def addNewTagForPodspecVersionAction() submit = getSubmitInfo() version = ActionHandler.getPodspecVersion() name = ActionHandler.getPodspecName() tag = "#{name}-#{version}" addCommand "git tag -a '#{tag}' -m '#{submit}'" addCommand "git push origin #{tag}" end |
#commitAction ⇒ Object
110 111 112 113 114 |
# File 'lib/sjpush.rb', line 110 def commitAction() submit = getSubmitInfo() addCommand "git add ." addCommand "git commit -m '#{submit}'" end |
#deleteTagAction ⇒ Object
138 139 140 141 142 143 |
# File 'lib/sjpush.rb', line 138 def deleteTagAction() puts "\n请输入要删除的标签:" tag = gets.strip! addCommand "git tag -d #{tag}" addCommand "git push origin :#{tag}" end |
#directReleaseAction ⇒ Object
一键发布
236 237 238 239 240 241 242 243 |
# File 'lib/sjpush.rb', line 236 def directReleaseAction() ActionHandler.updatePodspecVerAction() getSubmitInfo() commitAction() pushAction() addNewTagForPodspecVersionAction() podReleaseAction() end |
#executeCommands ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/sjpush.rb', line 156 def executeCommands puts " \n \n =========================\u6B63\u5219\u6267\u884C, \u8BF7\u7A0D\u7B49...=========================\n =========================\u6B63\u5219\u6267\u884C, \u8BF7\u7A0D\u7B49...=========================\n \n \n DESC\n system @commands\n puts \"\\n\u64CD\u4F5C\u5B8C\u6210\"\nend\n" |
#getCocoapodsRepo ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/sjpush.rb', line 92 def getCocoapodsRepo() if @repo.nil? puts "\n请输入仓库名:" @repo = gets.strip! end return @repo end |
#getSubmitInfo ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/sjpush.rb', line 84 def getSubmitInfo() if @commitInfo.nil? puts "\n请输入提交信息:" @commitInfo = gets.strip! end return @commitInfo end |
#handleSeq(seq) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/sjpush.rb', line 170 def handleSeq(seq) if seq == $seq_commit.to_i commitAction() elsif seq == $seq_push_current_branch.to_i pushAction() elsif seq == $seq_add_tag.to_i puts "\n是否使用Podspec中的版本作为标签? [ Yes / NO ]" r = gets if r.casecmp("Yes") == 1 addNewTagForPodspecVersionAction() else addNewTagAction() end elsif seq == $seq_release.to_i podReleaseAction() elsif seq == $seq_delete_tag.to_i deleteTagAction() elsif seq == $seq_update_podspec_version.to_i ActionHandler.updatePodspecVerAction() elsif seq == $seq_lazy_protocol.to_i require 'sjProtocol' exit elsif seq == $seq_lazy_property.to_i require 'sjScript' exit elsif seq = $seq_direct_release.to_i directReleaseAction() end nextCommand(seq) end |
#nextCommand(beforeSeq) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/sjpush.rb', line 203 def nextCommand(beforeSeq) if beforeSeq == $seq_commit.to_i # 询问是否推送到主干上 # ActionHandler - Push puts "\n是否推送到 #{ActionHandler.getCurBranch()}? [ Yes / NO ]" r = gets if r.casecmp("Yes") == 1 handleSeq($seq_push_current_branch.to_i) end elsif beforeSeq == $seq_push_current_branch.to_i puts "\n是否添加标签? [ Yes / NO ]" r = gets if r.casecmp("Yes") == 1 handleSeq($seq_add_tag.to_i) end elsif beforeSeq == $seq_add_tag.to_i # 询问是否发布pod # Pod - Release puts "\n是否发布pod版本? [ Yes / NO ]" r = gets if r.casecmp("Yes") == 1 handleSeq($seq_release.to_i) end elsif beforeSeq == $seq_update_podspec_version.to_i puts "\n是否提交变更? [ Yes / NO ]" r = gets if r.casecmp("Yes") == 1 handleSeq($seq_commit.to_i) end end end |
#podReleaseAction ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sjpush.rb', line 145 def podReleaseAction() spec = ActionHandler.getPodspec() if spec.nil? puts "\n已退出, 未搜索到 podspec 文件" exit end repo = getCocoapodsRepo() addCommand "pod repo push #{repo} #{spec} --allow-warnings --use-libraries --verbose --skip-import-validation" end |
#pushAction ⇒ Object
116 117 118 |
# File 'lib/sjpush.rb', line 116 def pushAction() addCommand "git push origin #{ActionHandler.getCurBranch()}" end |