sjpush 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sjpush.rb +195 -124
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7eec91405cf58e55fc5bd6de23cfc5f14a53bd99d897d65665472f97bcdc9278
4
- data.tar.gz: 2488a3f7ddc0f1b54b83f129446bc9733ae2ca8d1ef2bab3135b4bbeaef84042
3
+ metadata.gz: 9e1f8e002e9f71c269fc7d6ea03a49ff826073c2188551c67302cd5241a0750c
4
+ data.tar.gz: 96d0bae632e7786bd741df69dd10328e9f54c04b4d5bdb043fdca48ca01f5174
5
5
  SHA512:
6
- metadata.gz: 5cc6cf529702494115988457d12f73d9bea4169c2c7c17bbf18e5039a89dcc7bc4d2c13f67d0a557e46754d24d8d190c8cc34228a53371b95e30bb85aa7a329b
7
- data.tar.gz: 4a0c750272518cb84eb9607bce90dc1ddcf58219e8e1a91bfaed416ebef89259409df0e12ccab1a643d984b2eac95f4267e593c092d575c1c4ae100921497ca4
6
+ metadata.gz: d51fc71d1b75a2838adad014563ce560820a4f730048ff0e59c717957374267314893ecdde3e02723c93d0ad9b4957d26c27e40954a390b4a74541069ae0dd37
7
+ data.tar.gz: 6a2056029e7fb080d0c3f0e6a0a5aa3b44daf218f731753f7d3cf4f22a2f6402355ce2e333fd49269f14ef5a00e0302b2579ebf5463535abc16e2d7eaaf2b0e6
data/lib/sjpush.rb CHANGED
@@ -1,84 +1,132 @@
1
1
  #require "sjpush/version"
2
2
  #!/usr/bin/env ruby
3
3
 
4
- puts <<-DESC
5
- ===============================================
6
- 请输入操作序号:
7
- 1. 提交变更(git commit -m '..')
8
- 2. 推送到主干上(git push origin master)
9
- 3. 添加新的标签(git tag -a '..' -m '..')
10
- 4. pod发布(pod repo push ..repo ..podspec)
11
- 5. 删除标签(git -d .., git push origin :..)
12
-
13
- 补全代码:
14
- -1. 自动写协议
15
- -2. 自动补全懒加载
16
-
17
- 输入`exit`退出脚本
18
- ===============================================
19
- DESC
20
-
21
- $seq_git_commit = 1
22
- $seq_git_push_master = 2
23
- $seq_git_add_tag = 3
24
- $seq_pod_release = 4
25
- $seq_git_delete_tag = 5
26
-
27
- $seq_lazy_protocol = -1
28
- $seq_lazy_property = -2
4
+ class ActionHandler
5
+ # 定义类方法
6
+ class << self
7
+ # 获取当前的分支
8
+ def getCurBranch()
9
+ # strip! 删除开头和末尾的空白字符
10
+ commands = IO.readlines(".git/HEAD").first.strip!;
11
+ commands.sub!(/ref: refs\/heads\//, "")
12
+ end
13
+ end
29
14
 
30
- seq = gets
15
+ class << self
16
+ def getPodspec()
17
+ Dir["*.podspec"].last
18
+ end
31
19
 
32
- exit if seq.casecmp('exit') == 1
20
+ def updatePodspecVerAction()
21
+ s = ActionHandler.getPodspec()
22
+ if s.nil?
23
+ puts "已退出, 未搜索到 podspec 文件"
24
+ exit
25
+ end
26
+
27
+ contents = String.new
28
+ File.new(s, "r").each_line do |line|
29
+ regex = "s.version([^']+)'([^']+)'*"
30
+ if /#{regex}/ =~ line
31
+ v = ($2.to_i + 1).to_s
32
+ regex = "'[^']+'"
33
+ line = line.sub!(/#{regex}/, "'#{v}'")
34
+ end
35
+
36
+ contents += line
37
+ end
38
+ file = File.new(s, "w")
39
+ file.syswrite(contents)
40
+ file.close
41
+
42
+ puts "podspec 版本已更新"
43
+ end
44
+
45
+ def getPodspecVersion()
46
+ s = ActionHandler.getPodspec()
47
+ if s.nil?
48
+ puts "已退出, 未搜索到 podspec 文件"
49
+ exit
50
+ end
51
+
52
+ File.new(s, "r").each_line do |line|
53
+ regex = "s.version([^']+)'([^']+)'*"
54
+ if /#{regex}/ =~ line
55
+ @version = $2.to_i
56
+ break
57
+ end
58
+ end
59
+
60
+ return @version
61
+ end
62
+ end
33
63
 
34
- class Git
35
64
  def initialize()
36
- @content = String.new
65
+ @commands = String.new
37
66
  end
38
67
 
39
- def appendExeorder(order)
40
- if @content.length == 0
41
- @content << order
42
- else
43
- @content << " && #{order}"
68
+
69
+ # - Actions -
70
+
71
+ def addCommand(order)
72
+ if @commands.length == 0
73
+ @commands << order
74
+ else
75
+ @commands << " && #{order}"
44
76
  end
45
77
  end
46
-
47
- def commit()
48
- puts "请输入此次提交信息:"
49
- @commitInfo = gets.strip!
50
- appendExeorder "git add ."
51
- appendExeorder "git commit -m '#{@commitInfo}'"
78
+
79
+ def submitInfoAction()
80
+ if @commitInfo.nil?
81
+ puts "请输入提交信息:"
82
+ @commitInfo = gets.strip!
83
+ end
84
+ return @commitInfo
85
+ end
86
+
87
+ def commitAction()
88
+ submit = submitInfoAction()
89
+ addCommand "git add ."
90
+ addCommand "git commit -m '#{submit}'"
52
91
  end
53
92
 
54
- def pushMaster()
55
- appendExeorder "git push origin master"
93
+ def pushAction()
94
+ addCommand "git push origin #{ActionHandler.getCurBranch()}"
56
95
  end
57
96
 
58
- def addNewTag()
97
+ def addNewTagAction()
59
98
  puts "请输入新的标签:"
60
99
  newTag = gets.strip!
61
- appendExeorder "git tag -a '#{newTag}' -m '#{@commitInfo}'"
62
- appendExeorder "git push origin #{newTag}"
100
+
101
+ submit = submitInfoAction()
102
+ addCommand "git tag -a '#{newTag}' -m '#{submit}'"
103
+ addCommand "git push origin #{newTag}"
104
+ end
105
+
106
+ def addNewTagForPodspecVersionAction()
107
+ version = ActionHandler.getPodspecVersion()
108
+ submit = submitInfoAction()
109
+ addCommand "git tag -a '#{version}' -m '#{submit}'"
110
+ addCommand "git push origin #{version}"
63
111
  end
64
112
 
65
- def deleteTag()
113
+ def deleteTagAction()
66
114
  puts "请输入要删除的标签:"
67
115
  tag = gets.strip!
68
- appendExeorder "git tag -d #{tag}"
69
- appendExeorder "git push origin :#{tag}"
116
+ addCommand "git tag -d #{tag}"
117
+ addCommand "git push origin :#{tag}"
70
118
  end
71
119
 
72
- def podRelease()
73
- currentDir = Dir["*.podspec"].last
74
- if currentDir.nil?
75
- puts "已退出, 未搜索到 podsspec 文件"
120
+ def podReleaseAction()
121
+ s = ActionHandler.getPodspec()
122
+ if s.nil?
123
+ puts "已退出, 未搜索到 podspec 文件"
76
124
  exit
77
125
  end
78
- appendExeorder "pod repo push lanwuzheRepo #{currentDir} --allow-warnings --use-libraries"
126
+ addCommand "pod repo push lanwuzheRepo #{s} --allow-warnings --use-libraries"
79
127
  end
80
-
81
- def exec
128
+
129
+ def executeCommands
82
130
  puts <<-DESC
83
131
 
84
132
 
@@ -87,85 +135,108 @@ class Git
87
135
 
88
136
 
89
137
  DESC
90
- system @content
138
+ system @commands
91
139
  puts "操作完成"
92
140
  end
93
- end
94
141
 
95
142
 
96
- def whetherToPushMaster(git)
97
- # 询问是否推送到主干上
98
- # Git - Push
99
- puts "\n是否推送到 Master? [ Yes / NO ]"
100
- needPush = gets
101
- if needPush.casecmp("Yes") != 1
102
- git.exec
103
- exit
143
+ def handleSeq(seq)
144
+ if seq == $seq_commit.to_i
145
+ commitAction()
146
+ elsif seq == $seq_push_current_branch.to_i
147
+ pushAction()
148
+ elsif seq == $seq_add_tag.to_i
149
+ puts "\n是否使用Podspec中的版本作为标签? [ Yes / NO ]"
150
+ r = gets
151
+ if r.casecmp("Yes") == 1
152
+ addNewTagForPodspecVersionAction()
153
+ else
154
+ addNewTagAction()
155
+ end
156
+ elsif seq == $seq_release.to_i
157
+ podReleaseAction()
158
+ elsif seq == $seq_delete_tag.to_i
159
+ deleteTagAction()
160
+ elsif seq == $seq_update_podspec_version.to_i
161
+ ActionHandler.updatePodspecVerAction()
162
+ elsif seq == $seq_lazy_protocol.to_i
163
+ require 'sjProtocol'
164
+ exit
165
+ elsif seq == $seq_lazy_property.to_i
166
+ require 'sjScript'
167
+ exit
168
+ end
169
+
170
+ nextCommand(seq)
104
171
  end
105
- git.pushMaster
106
- end
107
172
 
108
- def whetherAddNewTag(git)
109
- # 询问是否添加新的标签
110
- # Git - Add Tag
111
- puts "\n是否添加标签? [ Yes / NO ]"
112
- needAddTag = gets
113
- if needAddTag.casecmp("Yes") != 1
114
- git.exec
115
- exit
116
- end
117
- git.addNewTag
118
- end
119
173
 
120
- def whetherReleasePod(git)
121
- # 询问是否发布pod
122
- # Pod - Release
123
- puts "\n是否发布pod版本? [ Yes / NO ]"
124
- needRelease = gets
125
- if needRelease.casecmp("Yes") != 1
126
- git.exec
127
- exit
174
+ def nextCommand(beforeSeq)
175
+ if beforeSeq == $seq_commit.to_i
176
+ # 询问是否推送到主干上
177
+ # ActionHandler - Push
178
+ puts "\n是否推送到 #{ActionHandler.getCurBranch()}? [ Yes / NO ]"
179
+ r = gets
180
+ if r.casecmp("Yes") == 1
181
+ handleSeq($seq_push_current_branch.to_i)
182
+ end
183
+ elsif beforeSeq == $seq_push_current_branch.to_i
184
+ puts "\n是否添加标签? [ Yes / NO ]"
185
+ r = gets
186
+ if r.casecmp("Yes") == 1
187
+ handleSeq($seq_add_tag.to_i)
188
+ end
189
+ elsif beforeSeq == $seq_add_tag.to_i
190
+ # 询问是否发布pod
191
+ # Pod - Release
192
+ puts "\n是否发布pod版本? [ Yes / NO ]"
193
+ r = gets
194
+ if r.casecmp("Yes") == 1
195
+ handleSeq($seq_release.to_i)
196
+ end
197
+ elsif beforeSeq == $seq_update_podspec_version.to_i
198
+ puts "\n是否提交变更? [ Yes / NO ]"
199
+ r = gets
200
+ if r.casecmp("Yes") == 1
201
+ handleSeq($seq_commit.to_i)
202
+ end
203
+ end
128
204
  end
129
- git.podRelease
130
205
  end
131
206
 
132
- def considerNextTask(beforeSeq, git)
133
- if beforeSeq == $seq_git_commit
134
- whetherToPushMaster(git)
135
- whetherAddNewTag(git)
136
- whetherReleasePod(git)
137
- elsif beforeSeq == $seq_git_push_master
138
- whetherAddNewTag(git)
139
- whetherReleasePod(git)
140
- elsif beforeSeq == $seq_git_add_tag
141
- whetherReleasePod(git)
142
- end
143
- end
207
+ seqs = [
208
+ $seq_update_podspec_version = "0. Podspec版本+1",
209
+ $seq_commit = "1. 提交变更",
210
+ $seq_push_current_branch = "2. 推送到当前分支(#{ActionHandler.getCurBranch()})",
211
+ $seq_add_tag = "3. 添加新的标签",
212
+ $seq_release = "4. pod发布(pod repo push ..repo ..podspec)",
213
+ $seq_delete_tag = "5. 删除标签",
214
+ $seq_lazy_protocol = "6. 自动写协议",
215
+ $seq_lazy_property = "7. 自动补全懒加载",
216
+ ]
144
217
 
145
- def handleSeq(seq)
146
- puts "\n\n"
147
-
148
- git = Git.new
149
- if seq == $seq_git_commit
150
- git.commit
151
- elsif seq == $seq_git_push_master
152
- git.pushMaster
153
- elsif seq == $seq_git_add_tag
154
- git.addNewTag
155
- elsif seq == $seq_pod_release
156
- git.podRelease
157
- elsif seq == $seq_git_delete_tag
158
- git.deleteTag
159
- elsif seq == $seq_lazy_protocol
160
- require 'sjProtocol'
161
- exit
162
- elsif seq == $seq_lazy_property
163
- require 'sjScript'
164
- exit
165
- end
166
-
167
- considerNextTask(seq, git)
168
- git.exec
218
+ require "pp"
219
+
220
+ # - seqs -
221
+ puts "\n"
222
+ puts "请输入操作序号:"
223
+ puts "\n"
224
+ seqs.each do |s|
225
+ puts s
169
226
  end
227
+ puts "\n"
228
+
229
+ # - exit -
230
+ puts "输入`exit`退出脚本"
231
+
232
+ puts "\n"
233
+ puts "================== 等待操作 =================="
234
+
235
+ seq = gets
236
+
237
+ exit if seq.casecmp('exit') == 1
170
238
 
171
- handleSeq(seq.to_i)
239
+ handler = ActionHandler.new
240
+ puts "\n\n"
241
+ handler.handleSeq(seq.to_i)
242
+ handler.executeCommands()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sjpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SanJiang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-17 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 用于辅助git提交
14
14
  email: