ZYPodWings 1.0.0

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/lib/ZYPodWings.rb +268 -0
  4. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 800c8cec6a23a0c5b5e9651246dfe01460e5ad7b325d369dccae8dd15e46be1e
4
+ data.tar.gz: 40887e3229b9e8a8691e964e34c8786dd1cd504138a966f68f0f833382407d48
5
+ SHA512:
6
+ metadata.gz: f64583406a9130792ca58abb874a8cd527560ae579f1f2c2d60a83fb139e7e9be21f51e6d7cc9c6a8c95f2559cfb588dc172fe9694b3302e7060b6d862e20015
7
+ data.tar.gz: a219292a81a047989a3e309daa92a863b2c1bc3b775738cf495f8533c493d93bc40e9cf79b65497f395f140e4fb404a3c7fc54b2b182084ab3eafda98729d15d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 WPJ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,268 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'json'
4
+
5
+ =begin
6
+ 使用方法:(共有两步)
7
+ 第一步:在podfile顶部加上引用下面2行代码
8
+ $LOAD_PATH << '.'
9
+ require 'ZYPodWings'
10
+ 第二步:在原本需要写 pod 命令处
11
+ 调用 pod_config 方法,默认使用 podConfig.json 文件,也可更换成指定的json配置文件
12
+
13
+
14
+
15
+ 目前可解析 pod 参数有
16
+ "enable": true, [必选] # 布尔值,是否启用,为 false 此仓库不会参与pod
17
+ "pod_name": "ZYPurchase", [必选] # 仓库名称
18
+ "is_github": false, [必选] # 是否是github库,即私有库统一为false
19
+ "is_release": false, [可选] # 是否是发布模式,本地调试用false,发布用true
20
+ "version": "1.0.8", [可选] # 版本号,github必选
21
+ "path": "../../ZYWidgets/ZYPurchase/", [可选] # 本地调试用 path 路径 私有pod必选
22
+ "git": "" [可选] # 远程 git 路径 私有pod必选
23
+ "auto_update_enable" [可选] # 是否响应自动更新, 默认为 false 不支持
24
+
25
+ Notice:
26
+ 1. 关于 is_github 和 is_release 的设置;
27
+ 1.1 is_github 表示仓库是否在 github 上,举例:Firebase 需要配置为 true,
28
+ 存放在 ZYPodSpecs 上面的和本地的统一为 false
29
+ 1.2 当 is_github 为 true 时设置 is_release 无效
30
+ 1.3 is_release 表示是否要从远程拉去代码,为 false 时从 path 目录下拉取代码
31
+
32
+ 对于 is_release 可搭配
33
+
34
+ 2. 关于 path 和 git 的配置;
35
+ path:本地路径, git:指远程 git 仓库地址
36
+ 建议用以下规范:
37
+ 2.1 github 为 true 的统一不用配置
38
+ 2.2 github 为 false 的情况,2个参数都需要配置,方便 is_release 参数切换
39
+ 3. auto_update_enable
40
+ 是否响应自动更新,当此参数表示是否在 ~/Desktop/{仓库名} 目录下寻找最新的版本并替换
41
+ =end
42
+
43
+ # pod 远程 git 仓库
44
+ def pod_remote(pod_info)
45
+ pod_name = pod_info["pod_name"]
46
+ # puts 'pod 远程仓库' + pod_name
47
+ version = pod_info["version"]
48
+ git_path = pod_info["git"]
49
+ if git_path && git_path.length > 0
50
+ commit = pod_info["commit"]
51
+ if commit && commit.length > 0
52
+ pod(pod_name, {:git => git_path, :commit => commit})
53
+ else
54
+ pod(pod_name, {:tag => version, :git => git_path})
55
+ end
56
+ else
57
+ pod(pod_name, version)
58
+ end
59
+ end
60
+
61
+ # pod 本地 git 仓库
62
+ def pod_local(pod_info)
63
+ pod_name = pod_info["pod_name"]
64
+ # puts 'pod 本地仓库' + pod_name
65
+ spec_path = pod_info["path"]
66
+ if spec_path.length > 0
67
+ pod(pod_name, {:path => spec_path})
68
+ else
69
+ puts "pod 本地仓库进行调试时,路径不能为空: " + pod_name
70
+ end
71
+ end
72
+
73
+ $spec_repo_path = File.expand_path('~/Desktop/ZYWidgets/ZYPodSpecs')
74
+ $pwd_path = Dir.pwd
75
+
76
+ # 获取 pod_name 的最新版本号
77
+ def last_version_for_pod(pod_name)
78
+ user_hub_path = File.join($spec_repo_path, pod_name)
79
+ versions = Dir::entries(user_hub_path)
80
+ last_version = fetch_last_version(versions)
81
+ # puts pod_name + '最新版本是:'+last_version
82
+ return last_version
83
+ end
84
+
85
+ # 更新podspec仓库
86
+ def pull_spec_repo()
87
+ spec_repo_exist = File.exist?($spec_repo_path)
88
+ unless spec_repo_exist
89
+ puts '本地 ~/Desktop/ZYWidgets/目录下没有ZYPodSpecs仓库,将不会更新私有pod版本号'
90
+ return false
91
+ end
92
+ Dir.chdir($spec_repo_path)
93
+ `git pull origin master`
94
+ Dir.chdir($pwd_path)
95
+ return true
96
+ end
97
+
98
+ # 更新json文件
99
+ def update_pod_list(json_file_path)
100
+ spec_repo_exist = File.exist?($spec_repo_path)
101
+ unless spec_repo_exist
102
+ puts '本地 ~/Desktop/ZYWidgets/目录下没有ZYPodSpecs仓库,将不会更新私有pod版本号'
103
+ return
104
+ end
105
+ pull_result = pull_spec_repo()
106
+ unless pull_result
107
+ puts 'pull ZYPodSpecs 失败了'
108
+ end
109
+ pod_list = JSON.parse(File.read(json_file_path))
110
+ unless pod_list.class == Array && pod_list.size > 0
111
+ puts "pod 配置文件格式有误或内容为空,将不会更新私有pod版本号"
112
+ return
113
+ end
114
+ json_changed = false
115
+ pod_list.each do |pod_dict|
116
+ is_avaliable = is_avaliable_pod_dict(pod_dict)
117
+ if not is_avaliable
118
+ next
119
+ end
120
+ enable = pod_dict.fetch("enable", false)
121
+ is_github = pod_dict.fetch('is_github', true)
122
+ auto_update_enable = pod_dict.fetch('auto_update_enable', false)
123
+ pod_name = pod_dict.fetch('pod_name')
124
+ if not pod_name or pod_name.length == 0
125
+ next
126
+ end
127
+ if not enable or is_github or not auto_update_enable
128
+ next
129
+ end
130
+ last_version = last_version_for_pod(pod_name)
131
+ if not last_version or last_version[0] == '.'
132
+ next
133
+ end
134
+ version = pod_dict.fetch('version', '1.0.0')
135
+ if not version == last_version
136
+ pod_dict["version"] = last_version
137
+ puts "#{pod_name} "
138
+ json_changed = true
139
+ end
140
+ end
141
+ if json_changed
142
+ File.open(json_file_path, 'w') { |json_file|
143
+ json_file.puts JSON.pretty_generate(pod_list)
144
+ }
145
+ end
146
+ end
147
+
148
+ # 开始pod
149
+ def start_pod(json_file_path, debug_list=[])
150
+ unless File.exist?(json_file_path)
151
+ puts "##### pod 配置文件不存在 >>>>>>>> "
152
+ return
153
+ end
154
+ pod_list = JSON.parse(File.read(json_file_path))
155
+ pod_list.each do |pod_info|
156
+ is_valid = is_avaliable_pod_dict(pod_info)
157
+ unless is_valid
158
+ next
159
+ end
160
+ enable = pod_info["enable"]
161
+ pod_name = pod_info["pod_name"]
162
+ unless enable
163
+ next
164
+ end
165
+ version = pod_info["version"]
166
+ is_github = pod_info["is_github"]
167
+ is_release = pod_info.fetch('is_release', true) #["is_release"]
168
+
169
+ if debug_list.include? pod_name and not is_github
170
+ # puts '##### Force debug >>>>>>>> ' + pod_name
171
+ is_release = false
172
+ end
173
+
174
+ if is_github
175
+ pod_remote(pod_info)
176
+ else
177
+ if is_release
178
+ pod_remote(pod_info)
179
+ else
180
+ pod_local(pod_info)
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ # pod 对应配置文件内容(供外部调用)
187
+ def pod_config(params={"file_name" => "podConfig.json", "update_to_last" => true, "local_pod_list" => []})
188
+ file_name = params.fetch("file_name", 'podConfig.json')
189
+ need_update_to_last = params.fetch("update_to_last", true)
190
+ local_pod_list = params.fetch("local_pod_list", [])
191
+
192
+ json_file_path = File.join($pwd_path, file_name)
193
+ # 更新json文件(若有必要)
194
+ if need_update_to_last
195
+ update_pod_list(json_file_path)
196
+ end
197
+
198
+ # 开始pod
199
+ start_pod(json_file_path, local_pod_list)
200
+ end
201
+
202
+ # 获取最新版本号
203
+ def fetch_last_version(versions)
204
+ if versions.length == 1
205
+ return versions[0]
206
+ end
207
+ last_version = versions[0]
208
+ (1..versions.size-1).each do |idx|
209
+ version = versions[idx]
210
+ if version[0] == '.'
211
+ next
212
+ end
213
+ last_version = compare_version(last_version, version)
214
+ end
215
+ return last_version
216
+ end
217
+
218
+ def compare_version(version0, version1)
219
+ if version0.length == 0
220
+ return version1
221
+ end
222
+ if version1.length == 0
223
+ return version0
224
+ end
225
+ if version0[0] == '.'
226
+ return version1
227
+ end
228
+ if version1[0] == '.'
229
+ return version0
230
+ end
231
+ ver0_arr = version0.split('.')
232
+ ver1_arr = version1.split('.')
233
+ if ver0_arr.size == 0 or ver1_arr.size == 0 or ver0_arr.size != ver1_arr.size
234
+ return version0
235
+ end
236
+ (0..ver0_arr.size-1).each do |idx|
237
+ num_0 = ver0_arr[idx].to_i()
238
+ num_1 = ver1_arr[idx].to_i()
239
+ if num_0 == num_1
240
+ next
241
+ end
242
+ if num_0 > num_1
243
+ return version0
244
+ else
245
+ return version1
246
+ end
247
+ end
248
+ end
249
+
250
+ def is_avaliable_pod_dict(pod_dict)
251
+ if not pod_dict
252
+ return false
253
+ end
254
+ all_keys = pod_dict.keys()
255
+ if not all_keys.include?('enable')
256
+ return false
257
+ end
258
+ if not all_keys.include?('is_github')
259
+ return false
260
+ end
261
+ if not all_keys.include?('pod_name')
262
+ return false
263
+ end
264
+ if not all_keys.include?('version')
265
+ return false
266
+ end
267
+ return true
268
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ZYPodWings
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wupengju
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Efficiency improvement for iOS modular development with cocoa pods.
14
+ email: 331321408@qq.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - lib/ZYPodWings.rb
21
+ homepage: https://github.com/coderWPJ/ZYPodWings.git
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Efficiency improvement for iOS modular development with cocoa pods.
44
+ test_files: []