cocoapods-hd 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffd2d68ac7c36de3ac542b45d7e322ff0714aa513ec0c8e2a9974bcbccc943bb
4
+ data.tar.gz: 417cfeb3b4cf1c9ae2f6d2910263fb18cd0344c61d0b555e701c01b6317f1f98
5
+ SHA512:
6
+ metadata.gz: 1f7691e3318db964c3c4269449cce8ed13ac8a4305dc1ea2e2a3627d5711118901a7b9ea5f2b8e339c2b6301beea43485ceb94d20468f581ea72b573f3fda277
7
+ data.tar.gz: e4cc634db1c522e45960e34db2094ecb983abe85ae8cb47fc6f2eb814ddee3c7cbe57243ba64f32c272ddfa3ee863d4fce4a6c7fa9a9fd31ad70b8fff0b364ba
@@ -0,0 +1 @@
1
+ require 'cocoapods-hd/gem_version'
@@ -0,0 +1,3 @@
1
+ require 'cocoapods-hd/command/hd'
2
+ require 'cocoapods-hd/command/tag'
3
+ require 'cocoapods-hd/tag_util'
@@ -0,0 +1,45 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class Hd < Command
21
+ self.summary = 'cocoapods-hd 功能简介'
22
+
23
+ self.description = <<-DESC
24
+ hd 插件测试功能描述
25
+ DESC
26
+
27
+ # self.arguments = 'NAME'
28
+
29
+ def initialize(argv)
30
+ @name = argv.shift_argument
31
+ super
32
+ end
33
+
34
+ def validate!
35
+ super
36
+ help! 'A Pod name is required.' unless @name
37
+ end
38
+
39
+ def run
40
+ UI.puts "=========测试======"
41
+ UI.puts "Add your --- implementation for the cocoapods-hd plugin in #{__FILE__}"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,202 @@
1
+ require 'cocoapods'
2
+ require 'fileutils'
3
+
4
+ module Pod
5
+ class Command
6
+ class Tag < Command
7
+
8
+ self.summary = 'tag相关操作'
9
+ self.description = <<-DESC
10
+ tag创建、删除
11
+ DESC
12
+
13
+ def self.options
14
+ [
15
+ ['--beta', 'beta tag'],
16
+ ['--create', 'create tag'],
17
+ ['--delete', 'delete tag and remove pod repo source'],
18
+ ]
19
+ end
20
+
21
+ def initialize(argv)
22
+ @beta = argv.flag?('beta', false)
23
+ @create = argv.flag?('create', false)
24
+ @delete = argv.flag?('delete', false)
25
+ @tag_version = argv.shift_argument
26
+ # @tag_version = argv.option('tag_version') || nil
27
+ # @tag_version = argv.arguments! unless argv.arguments.empty?
28
+ super
29
+ end
30
+
31
+ # 创建tag
32
+ def create_tag
33
+
34
+ unless TagUtil.exist_branch
35
+ UI.warn("当前分支名格式不正确,请修改为 release_x.x.x 格式")
36
+ return
37
+ end
38
+ unless TagUtil.check_branch_include_tag(@tag_version)
39
+ UI.warn("分支后缀版本号,必须跟tag保持一致")
40
+ return
41
+ end
42
+
43
+ UI.puts "🍉 开始创建tag: #{get_tag}"
44
+
45
+ if TagUtil.exist_tag(get_tag)
46
+ TagUtil.git_delete_tag(get_tag)
47
+ end
48
+
49
+ `git tag #{get_tag}`
50
+ `git push origin #{get_tag}`
51
+
52
+ latest_tag = %x(git describe --abbrev=0 --tags 2>/dev/null)
53
+ UI.puts("--------- latest tag ----------")
54
+ UI.puts(latest_tag)
55
+ unless get_tag.eql?(latest_tag.to_s.strip)
56
+ TagUtil.git_delete_tag(get_tag)
57
+ UI.warn("⚠️ commit没有改变,请先提交内容")
58
+ return
59
+ end
60
+
61
+ module_dir = Dir.pwd
62
+
63
+ Dir['*.podspec'].each do |rip|
64
+ podspec_name = rip.to_s
65
+ if podspec_name.empty?
66
+ UI.warn("#{module_dir}目录下,不包含.podspec文件")
67
+ return
68
+ end
69
+
70
+ podspec_json_name = "#{podspec_name}.json"
71
+ pod_name = podspec_name.gsub(".podspec", "")
72
+ `pod ipc spec #{pod_name}.podspec >>#{podspec_json_name}`
73
+ podspec_json_dir = File.join(Dir.pwd, podspec_json_name)
74
+
75
+ source_specs_dir = get_source_specs_dir
76
+
77
+ UI.puts("HDSourceSpecs目录: #{source_specs_dir}")
78
+
79
+ Dir.chdir(source_specs_dir)
80
+ `git pull`
81
+
82
+ dest_dir = File.join(source_specs_dir, pod_name, get_tag)
83
+
84
+ UI.section("创建目录: #{dest_dir}") do
85
+ FileUtils.mkdir(dest_dir) unless File.directory? dest_dir
86
+ end
87
+
88
+ UI.section("move #{podspec_json_dir} to #{dest_dir}") do
89
+ FileUtils.mv(podspec_json_dir, dest_dir)
90
+ end
91
+
92
+ UI.section("✅ #{podspec_json_name} 上传成功") do
93
+ `git status -s`
94
+ `git add .`
95
+ `git commit -m 'add #{pod_name} #{get_tag}'`
96
+ `git push origin master`
97
+ end
98
+
99
+ Dir.chdir(module_dir)
100
+ end
101
+ unless exist_cocoapods_source_dir
102
+ module_parent_dir = File.expand_path("..", Dir.pwd) # ~/debug-cocoapods-hd
103
+ source_repo_path = File.join(module_parent_dir, "HDSourceSpecs")
104
+ FileUtils.rm_r(source_repo_path)
105
+ end
106
+
107
+ unless @beta
108
+ beta_tag = "#{@tag_version}-beta"
109
+ if TagUtil.exist_tag(beta_tag)
110
+ UI.section("正式tag #{@tag_version} 创建成功,删除#{@tag_version}-beta") do
111
+ delete_tag(beta_tag)
112
+ end
113
+ end
114
+
115
+ end
116
+ end
117
+
118
+ # 获取 HDSourceSpecs 路径
119
+ def get_source_specs_dir
120
+
121
+ if File.directory?(cocoapods_repos_dir)
122
+ cocoapods_repos_dir
123
+ else
124
+ module_parent_dir = File.expand_path("..", Dir.pwd) # module目录的上一级
125
+ source_repo_path = File.join(module_parent_dir, "HDSourceSpecs")
126
+
127
+ if File.exist?(source_repo_path)
128
+ source_repo_path
129
+ else
130
+ Dir.chdir(module_parent_dir)
131
+ `git clone http://gitlab.dushuclub.io/cocoapods/HDSourceSpecs.git`
132
+ source_repo_path
133
+ end
134
+ end
135
+ end
136
+
137
+ # 移除tag
138
+ def delete_tag(tag)
139
+ UI.puts "🍉 开始删除tag: #{tag}"
140
+ if TagUtil.exist_tag(tag)
141
+ TagUtil.git_delete_tag(tag)
142
+ remove_pod_repo_source(tag)
143
+ else
144
+ UI.warn "❌ 不存在tag: #{tag}"
145
+ end
146
+ end
147
+
148
+ # 获取tag名称
149
+ def get_tag
150
+ @beta ? "#{@tag_version}-beta" : @tag_version
151
+ end
152
+
153
+ # 移除远程仓库podspec
154
+ def remove_pod_repo_source(tag_name)
155
+
156
+ Dir['*.podspec'].each do |rip|
157
+ pod_name = rip.to_s.gsub(".podspec", "")
158
+ UI.puts "pod_name: #{pod_name}"
159
+
160
+ unless File.directory?(cocoapods_repos_dir)
161
+ Pod::UI.puts "本地 HDSourceSpecs not found"
162
+ break
163
+ end
164
+
165
+ full_path = File.join(cocoapods_repos_dir, pod_name, tag_name)
166
+
167
+ unless File.exist?(full_path)
168
+ UI.warn "❌ 本地HDSourceSpecs不包含#{pod_name}的#{tag_name}标签, 请先执行 pod repo update"
169
+ break
170
+ end
171
+ FileUtils.remove_dir(full_path)
172
+ Dir.chdir(cocoapods_repos_dir)
173
+ # UI.puts "切换到:#{Dir.pwd}"
174
+ UI.section("✅ #{pod_name} #{tag_name} 标签删除成功 !!!") do
175
+ `git pull origin master`
176
+ `git add .`
177
+ `git commit -m '删除#{pod_name}/#{tag_name}'`
178
+ `git push origin master`
179
+ end
180
+
181
+ end
182
+ end
183
+
184
+ def cocoapods_repos_dir
185
+ File.join(Dir.home, ".cocoapods/repos/HDSourceSpecs")
186
+ end
187
+
188
+ def exist_cocoapods_source_dir
189
+ File.directory?(cocoapods_repos_dir)
190
+ end
191
+
192
+ def run
193
+ if @delete
194
+ delete_tag(get_tag)
195
+ else
196
+ create_tag
197
+ end
198
+ end
199
+ end
200
+ end
201
+
202
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsHd
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class TagUtil
5
+ # attr_accessor :test
6
+ # def initialize(test)
7
+ # @test = test
8
+ # end
9
+
10
+ # tag 是否存在
11
+ def self.exist_tag(tag)
12
+ tag_string = `git tag -l`
13
+ tag_list = tag_string.to_s.split("\n")
14
+ tag_list.include?(tag)
15
+ end
16
+
17
+ def self.git_delete_tag(tag)
18
+ `git tag -d #{tag}`
19
+ `git push origin :refs/tags/#{tag}`
20
+ end
21
+
22
+ # tag 是否存在符合格式的分支
23
+ def self.exist_branch
24
+ branch_name = `git symbolic-ref --short -q HEAD`
25
+ UI.puts("current branch: #{branch_name}")
26
+ if branch_name =~ /release_[0-9].[0-9].[0-9]/ || branch_name.to_s.strip == "master"
27
+ return true
28
+ end
29
+ false
30
+ end
31
+
32
+ def self.check_branch_include_tag(tag)
33
+ branch_name = `git symbolic-ref --short -q HEAD`
34
+ if branch_name.to_s.strip == "master"
35
+ return true
36
+ end
37
+ if branch_name.include?(tag.to_s)
38
+ return true
39
+ end
40
+ false
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,9 @@
1
+ require 'cocoapods-hd/command'
2
+ require 'cocoapods'
3
+
4
+ module Hd
5
+ # 注册 pod install 钩子
6
+ Pod::HooksManager.register('cocoapods-hd', :post_install) do |context|
7
+ Pod::UI.puts 'hello world ---'
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-hd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - xingyong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.11
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.11
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.3
41
+ description: 组件化开发工具
42
+ email:
43
+ - xingyong@dushu365.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-hd.rb
49
+ - lib/cocoapods-hd/command.rb
50
+ - lib/cocoapods-hd/command/hd.rb
51
+ - lib/cocoapods-hd/command/tag.rb
52
+ - lib/cocoapods-hd/gem_version.rb
53
+ - lib/cocoapods-hd/tag_util.rb
54
+ - lib/cocoapods_plugin.rb
55
+ homepage: https://juejin.cn/post/6931272510793383943
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.1.4
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: 组件化开发工具,快速创建和删除tag
78
+ test_files: []