cocoapods-tag 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fc5297e51950ca49c7e6862bcd9ccaa7707c88b1568df30ed32cc165cb05d48
4
- data.tar.gz: adf8df13f96690d4d98eeb08d801d7570f255eabc8d16ad395ccfb71d7815fd5
3
+ metadata.gz: 3e08286edd1ef94599d7c41fee1be27a19b816f4ef414e2ff4f13458d140b883
4
+ data.tar.gz: 4513e86cf577e8965fc18db0bc123a302ca58f8a4a80bdd3e459547eac0e99f3
5
5
  SHA512:
6
- metadata.gz: 9cd6328f564dcfe676bd940258a0a1d8701ecc1eff4451fa856c6808cb64d475d2659db869424ee316ecdcb589533ee37b045dfb1ea1b3a2b779c5cadb715713
7
- data.tar.gz: 1e83a70c3ea110853d6fa97ef376cd121848567ec681b08949de3c0f2bde6e6b14fd660abbd4313de613523d72f6848baeb08b8a884d746841aba3b9584c59b2
6
+ metadata.gz: acbeb468411de55cc4cf718caa298dbad09836d425986859f642ca50a8c17329fa47f8c09aa9b36dde2aa8161d82a95676236b8caf8701f730e67b86e2115547
7
+ data.tar.gz: b1ee42a404c0bad37eff6ee43ddb528d79001055a68d36cde70c619093837c40d1e59a55d7ff27d6c6d133665e7b0ee2e58aaca8b93691bd24e1f165f98e406b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## 简介
2
2
 
3
- `cocoapods-tag`是一个可以方便地帮助Pod库打tag的`CocoaPods`插件,插件采用问答的方式提示用户输入相应内容,简单、方便、快捷。
3
+ `cocoapods-tag`是一个可以方便地帮助Pod库打tag的`CocoaPods`插件。
4
4
 
5
5
  ## 安装
6
6
 
@@ -12,25 +12,42 @@ $ gem install cocoapods-tag
12
12
 
13
13
  * 查看帮助
14
14
 
15
- ```shell
16
- $ pod tag --help
17
- ```
15
+ ```shell
16
+ $ pod tag --help
17
+ $ pod tag auto --help
18
+ ```
18
19
 
19
- * 创建tag并push到远端,并询问是否上传podspec到spec repo
20
+ * 使用默认tag信息,如tag为“0.1.7”,那么tag信息为”v0.1.7“
20
21
 
21
- ```shell
22
- $ pod tag
23
- # 或
24
- $ pod tag create
25
- ```
22
+ ```shell
23
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7"
24
+ ```
26
25
 
27
- * 上传podspec到spec repo
26
+ * 使用自定义tag信息
28
27
 
29
- ```shell
30
- $ pod tag spec-push REPO NAME.podspec
31
- ```
28
+ ```shell
29
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7"
30
+ ```
31
+
32
+ * 推送`podspec`到指定的`spec repo`
33
+
34
+ ```shell
35
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx
36
+ ```
37
+
38
+ * 跳过耗时校验
39
+
40
+ ```shell
41
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx --quick
42
+ ```
43
+
44
+ * 单独推送`podspec`到指定`spec repo`
45
+
46
+ ```shell
47
+ $ pod tag spec-push REPO NAME.podspec
48
+ ```
49
+
50
+ > 如有疑问,请使用`pod tag auto --help`查看帮助信息,里面有每个字段的解释
32
51
 
33
- ## 演示gif
34
52
 
35
- <img src='./cocoapods-tag.gif' width='100%' />
36
53
 
@@ -0,0 +1,59 @@
1
+ require 'cocoapods-tag/tag'
2
+
3
+ module Pod
4
+ class Command
5
+ class Tag < Command
6
+ class Auto < Tag
7
+ include Pod
8
+
9
+ self.summary = '创建 tag 并 push 到远端仓库,同时可以上传 podspec 到 spec repo'
10
+
11
+ self.description = <<-DESC
12
+ #{self.summary}
13
+
14
+ `TAG`: tag号【必填】\n
15
+ `COMMIT_MSG`: commit信息【必填】\n
16
+ `TAG_MSG`: tag信息【可选,默认为"v[tag号]",比如:tag是"0.0.1",则tag信息是"v0.0.1"】\n
17
+
18
+ eg:\n
19
+ 1.使用默认tag信息\n
20
+ pod tag 0.1.7 "修改podspec版本号为0.1.7"\n
21
+ 2.使用自定义tag信息\n
22
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7"\n
23
+ 3.推送podspec到spec repo\n
24
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx\n
25
+ 4.跳过耗时校验\n
26
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx --quick
27
+ DESC
28
+
29
+ self.arguments = [
30
+ CLAide::Argument.new('TAG', true ),
31
+ CLAide::Argument.new('COMMIT_MSG', true),
32
+ CLAide::Argument.new('TAG_MSG', false)
33
+ ]
34
+
35
+ def self.options
36
+ [
37
+ ['--spec-repo=SPECREPO', 'podspec 推送到的 spec repo ,可以通过`pod repo list`查看'],
38
+ ['--quick', '跳过一些耗时校验,如:远端仓库是否已经有该 tag ']
39
+ ].concat(super)
40
+ end
41
+
42
+ def initialize(argv)
43
+ @tag = argv.shift_argument
44
+ @commit_msg = argv.shift_argument
45
+ @tag_msg = argv.shift_argument
46
+ @spec_repo = argv.option('spec-repo', nil)
47
+ @quick = argv.flag?('quick', false)
48
+ super
49
+ end
50
+
51
+ def run
52
+ tag = Pod::Tag.new(@tag, @commit_msg, @tag_msg, @spec_repo, @quick)
53
+ tag.create
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -10,7 +10,7 @@ module Pod
10
10
  GIT_REPO = ".git".freeze
11
11
  PODSPEC_EXT = %w[podspec podspec.json].freeze
12
12
 
13
- self.summary = '创建 tag 并 push 到远端仓库,同时可以上传 podspec 到 spec repo'
13
+ self.summary = '【问答的方式】创建 tag 并 push 到远端仓库,同时可以上传 podspec 到 spec repo'
14
14
 
15
15
  self.description = <<-DESC
16
16
  #{self.summary}
@@ -241,13 +241,13 @@ module Pod
241
241
  print "推送commit到远端git仓库`#{@remote}/#{current_branch}`失败:#{e}".red
242
242
  end
243
243
 
244
- print "\n创建tag:#{@tag}并推送至远端:\n".yellow
244
+ print "\n创建tag:`#{@tag}`并推送至远端:\n".yellow
245
245
  begin
246
246
  `git tag -a #{@tag} -m #{@tag_msg}`
247
247
  `git push #{@remote} --tags`
248
248
  rescue Pod::StandardError => e
249
249
  @error = e
250
- print "创建tag:#{@tag}并推送至远端失败:#{e}".red
250
+ print "创建tag:`#{@tag}`并推送至远端失败:#{e}".red
251
251
  end
252
252
  end
253
253
 
@@ -1,4 +1,5 @@
1
- require 'cocoapods-tag/command/tag/create'
1
+ require 'cocoapods-tag/command/tag/auto'
2
+ # require 'cocoapods-tag/command/tag/create'
2
3
  require 'cocoapods-tag/command/tag/spec_push'
3
4
 
4
5
  module Pod
@@ -6,7 +7,7 @@ module Pod
6
7
  class Tag < Command
7
8
 
8
9
  self.abstract_command = true
9
- self.default_subcommand = 'create'
10
+ self.default_subcommand = 'auto'
10
11
 
11
12
  self.summary = '🚀 方便地帮助 pod 库打 tag'
12
13
  self.description = <<-DESC
@@ -1,3 +1,3 @@
1
1
  module CocoapodsTag
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,276 @@
1
+ require 'cocoapods-tag/helper/asker'
2
+
3
+ module Pod
4
+ class Tag
5
+ include Pod
6
+
7
+ GITHUB_DOMAIN = "github.com".freeze
8
+ GIT_REPO = ".git".freeze
9
+ PODSPEC_EXT = %w[podspec podspec.json].freeze
10
+
11
+ def initialize(tag, commit_msg, tag_msg, spec_repo = nil, quick = false)
12
+ @tag = tag || raise(Informative, "缺少必填参数`tag`")
13
+ @commit_msg = commit_msg || raise(Informative, "缺少必填参数`commit_msg`")
14
+ @tag_msg = tag_msg || "v#{@tag}"
15
+ @spec_repo = spec_repo
16
+ @quick = quick
17
+ end
18
+
19
+ public
20
+
21
+ def create
22
+ require 'cocoapods-tag/native/validator'
23
+
24
+ # 欢迎语
25
+ welcome_message
26
+ # 检查本地是否有 spec_repo
27
+ check_spec_repo if @spec_repo
28
+ # 检查 git repo
29
+ check_git_repo
30
+ # 加载 podspec
31
+ load_podspec
32
+ # 校验 podspec
33
+ lint_podspec
34
+ # 修改 podspec
35
+ modify_podspec
36
+ # 推送 commit 到远端
37
+ git_commit_push
38
+ # 推送 tag 到远端
39
+ git_tag_push
40
+ # 推送 podspec 到 spec repo
41
+ push_podspec_to_repo if @spec_repo
42
+ # 结束语
43
+ done_message
44
+ end
45
+
46
+ private
47
+
48
+ def welcome_message
49
+ message = <<-MSG
50
+ 👏🏻欢迎使用 `cocoapods-tag` 插件👏🏻
51
+ 👏🏻version: #{CocoapodsTag::VERSION}👏🏻
52
+
53
+ MSG
54
+ print message.green
55
+ end
56
+
57
+ def done_message
58
+ print "\n🌺 恭喜你完成任务 🌺\n".green
59
+ end
60
+
61
+ # 检查本地 spec_repo
62
+ def check_spec_repo
63
+ print "检查本地spec仓库\n".yellow
64
+ repos = `pod repo list`.split("\n").reject { |repo| repo == '' || repo =~ /^-/ }
65
+ unless repos.include?(@spec_repo)
66
+ raise Informative, "本地不存在`#{@spec_repo}`仓库,请先使用`pod repo add`添加该仓库或使用`pod repo list`查看其他仓库"
67
+ end
68
+ end
69
+
70
+ # 检查 git repo
71
+ def check_git_repo
72
+ # print "检查本地git仓库:\n".yellow
73
+
74
+ # 本地是否有 .git 目录
75
+ git_repo = File.join(Dir.pwd, GIT_REPO)
76
+ raise Informative, "`#{Dir.pwd}`不存在git仓库,请先使用`git init`初始化git仓库" unless File.exist?(git_repo)
77
+
78
+ # 是否与远端仓库关联
79
+ raise Informative, "本地git仓库没有与远端仓库关联,请先使用`git remote add`关联远端仓库" if remote.nil?
80
+
81
+ unless @quick
82
+ # 校验本地 git 是否与远端仓库同步
83
+ print "\n检查本地git仓库是否与远端仓库同步\n".yellow
84
+ local_commit = `git rev-parse #{remote}/HEAD`.chomp
85
+ remote_commit = `git ls-remote --head #{remote} #{current_branch}`.split("\t")[0]
86
+ unless local_commit == remote_commit
87
+ msg = <<-MSG
88
+ 本地git仓库没有与远端仓库同步,请先执行以下操作:
89
+ 1.`git pull`或`git fetch + git rebase`拉取最新代码
90
+ 2.`git push`推送本地仓库commit
91
+ MSG
92
+ raise Informative, msg
93
+ end
94
+
95
+ # 检查本地是否已经有该 tag
96
+ print "\n检查本地仓库是否有tag:`#{@tag}`\n".yellow
97
+ raise Informative, "本地已经存在 tag:#{@tag}" if `git tag`.split("\n").include?(@tag)
98
+
99
+ # 判断远端是否已经有该 tag
100
+ print "\n检查远端仓库是否有tag:`#{@tag}`\n".yellow
101
+ tags = `git ls-remote --tags #{remote}`.split("\n").select { |tag| tag.include?("refs/tags/#{@tag}") }
102
+ raise Informative, "远端仓库已经有该 tag:#{@tag}" unless tags.empty?
103
+ end
104
+
105
+ end
106
+
107
+ # 加载 podspec
108
+ def load_podspec
109
+ raise Informative, "`#{Dir.pwd}`不存在podspec" if podspec.nil?
110
+
111
+ @spec = Specification.from_file(podspec)
112
+ raise Informative, "加载`#{podspec}`失败!" if @spec.nil?
113
+
114
+ @spec_hash = @spec.to_hash
115
+ source = @spec_hash['source']
116
+ # 目前只处理 git 这种形式
117
+ unless source['git']
118
+ raise Informative, "目前只能处理`git`这种形式"
119
+ end
120
+ # git字段为空
121
+ if source['git'] && source['git'].strip == ''
122
+ raise Informative, "source中git字段不能为空"
123
+ end
124
+ end
125
+
126
+ # 修改podspec
127
+ def modify_podspec
128
+ return if podspec.nil?
129
+
130
+ print "\n修改`#{podspec}`\n".yellow
131
+ file = File.join(Dir.pwd, "#{podspec}")
132
+ # 匹配文件名后缀
133
+ if podspec =~ /.podspec$/
134
+ modify_podspec_ruby(file)
135
+ elsif podspec =~ /.podspec.json$/
136
+ modify_podspec_json(file)
137
+ end
138
+ print "`#{podspec}` modified done\n"
139
+ end
140
+
141
+ # 修改 *.podspec
142
+ def modify_podspec_ruby(file)
143
+ org_source = @spec_hash['source']
144
+ des_source = "{ :git => '#{org_source['git']}', :tag => '#{@tag}' }"
145
+ File.open(file, 'r') do |f|
146
+ lines = []
147
+ f.each_line do |line|
148
+ if line =~ /(^\s*.+\.version\s*=\s*).*/
149
+ line = line.sub(/(^\s*.+\.version\s*=\s*).*/, "#{$1}'#{@tag}'")
150
+ end
151
+ if line =~ /(^\s*.+\.source\s*=\s*).*/
152
+ line = line.sub(/(^\s*.+\.source\s*=\s*).*/, "#{$1}#{des_source}")
153
+ end
154
+ lines << line
155
+ end
156
+ File.open(file, 'w') do |f|
157
+ f.write(lines.join(""))
158
+ end
159
+ end
160
+ end
161
+
162
+ # 修改 *.podspec.json
163
+ def modify_podspec_json(file)
164
+ @spec_hash['version'] = @tag
165
+ @spec_hash['source'] = {
166
+ 'git'=> @spec_hash['source']['git'],
167
+ 'tag'=> "#{@tag}"
168
+ }
169
+ File.open(file, 'w') do |f|
170
+ f.write(@spec_hash)
171
+ end
172
+ end
173
+
174
+ # 推送 commit
175
+ def git_commit_push
176
+ print "\n推送commit到远端git仓库`#{remote}/#{current_branch}`\n".yellow
177
+ begin
178
+ `git add #{podspec}`
179
+ `git commit -m "#{@commit_msg}"`
180
+ `git push #{remote} #{current_branch}`
181
+ rescue Pod::StandardError => e
182
+ @error = e
183
+ print "推送commit到远端git仓库`#{remote}/#{current_branch}`失败:#{e}".red
184
+ end
185
+ end
186
+
187
+ # 推送 tag 到远端
188
+ def git_tag_push
189
+ print "\n创建tag:`#{@tag}`并推送至远端`#{remote}`\n".yellow
190
+ begin
191
+ `git tag -a #{@tag} -m "#{@tag_msg}"`
192
+ `git push #{remote} #{@tag}`
193
+ rescue Pod::StandardError => e
194
+ @error = e
195
+ print "创建tag:`#{@tag}`并推送至远端失败:#{e}".red
196
+ end
197
+ end
198
+
199
+ # 推送 podspec 到 spec repo
200
+ def push_podspec_to_repo
201
+ print "\n推送`#{podspec}`到`#{@spec_repo}`仓库\n".yellow
202
+ argvs = [
203
+ @spec_repo,
204
+ podspec,
205
+ '--allow-warnings'
206
+ ]
207
+ begin
208
+ push = Pod::Command::Repo::Push.new(CLAide::ARGV.new(argvs))
209
+ push.validate!
210
+ push.run
211
+ rescue Pod::StandardError => e
212
+ @error = e
213
+ print "推送`#{podspec}`到`#{@spec_repo}`仓库失败!#{e}".red
214
+ end
215
+ end
216
+
217
+ # 校验 podspec
218
+ def lint_podspec(tip = "\n校验`#{podspec}`\n")
219
+ print "#{tip}".yellow
220
+ argvs = [
221
+ podspec,
222
+ '--quick',
223
+ '--allow-warnings'
224
+ ]
225
+ lint = Pod::Command::Spec::Lint.new(CLAide::ARGV.new(argvs))
226
+ lint.validate!
227
+ lint.run
228
+ end
229
+
230
+ # 获取当前分支
231
+ def current_branch
232
+ @current_branch ||= begin
233
+ `git branch`.split(' ')[1]
234
+ end
235
+ end
236
+
237
+ # 获取当前目录下的 podspec
238
+ def podspec
239
+ @podspec ||= begin
240
+ podspec = nil
241
+ podspecs = Dir.glob("*.{#{PODSPEC_EXT.join(',')}}")
242
+ unless podspecs.empty?
243
+ podspec = podspecs.first
244
+ end
245
+ podspec
246
+ end
247
+ end
248
+
249
+ def asker
250
+ @asker ||= begin
251
+ Helper::Asker.new()
252
+ end
253
+ end
254
+
255
+ # 获取远端仓库名
256
+ def remote
257
+ @remote ||= begin
258
+ remote = nil
259
+ remotes = `git remote`.split("\n")
260
+ remote = remotes.first unless remotes.empty?
261
+ if remotes.size > 1
262
+ count = 0
263
+ selections = {}
264
+ remotes.map do |r|
265
+ count += 1
266
+ selections["#{count}"] = r
267
+ end
268
+ key = asker.ask("\n本地有多个关联的远端仓库,请选择:", true, nil, selections)
269
+ remote = remotes["#{key}".to_i - 1]
270
+ end
271
+ remote
272
+ end
273
+ end
274
+
275
+ end
276
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -64,11 +64,13 @@ files:
64
64
  - lib/cocoapods-tag.rb
65
65
  - lib/cocoapods-tag/command.rb
66
66
  - lib/cocoapods-tag/command/tag.rb
67
+ - lib/cocoapods-tag/command/tag/auto.rb
67
68
  - lib/cocoapods-tag/command/tag/create.rb
68
69
  - lib/cocoapods-tag/command/tag/spec_push.rb
69
70
  - lib/cocoapods-tag/gem_version.rb
70
71
  - lib/cocoapods-tag/helper/asker.rb
71
72
  - lib/cocoapods-tag/native/validator.rb
73
+ - lib/cocoapods-tag/tag.rb
72
74
  - lib/cocoapods_plugin.rb
73
75
  - spec/command/tag_spec.rb
74
76
  - spec/spec_helper.rb