cocoapods-TSPodfileTimeWatch 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c1c799547f6b0af443869a0c5f264e27e8887a976718576e33da494f2bab4ab
4
- data.tar.gz: 8d6c7a5e9f35f833122def3143184c15ebf88b14c8b628c82ff1e2ae262c7d81
3
+ metadata.gz: 05f3029a264c746bad75546fd5078dad1b3c4a52df5b8e84213bf496f2b95b44
4
+ data.tar.gz: 4a9178680d3a2b55e0d140f73d6d6efad3d8d80617fc773a813dc0b93007a174
5
5
  SHA512:
6
- metadata.gz: 273fe76b9b43e5a3a0072072b8c3d5fff6518294f5376712667f15de26ce09cdd216fdf8ddcea3626e5d851871d57201df519ca259aaa69750e93164c1f467da
7
- data.tar.gz: 17bddcc381c6f3dd3c4072ad9a9ccb4f85189b47be789e3604ac815833bf7b42635186b3b241bf8accddff0f0c7e729ca53d63c1817c6dfc3c85720bab5e78b5
6
+ metadata.gz: 1c97101f15106ce4c16bc96b36eef69592741a63423d46ea160fa1c5271604755b62d3e1ed152e75ebb05cb6f133f9546151a90ca758adcd960b44e4d325b380
7
+ data.tar.gz: bca7180391d7a8b0860fce2d871c1ead8f8841944774b60b7ab5ad33b1ca890abf404500e29e66abdc624b315f94766f02592cba43f95a6f3283515be02b57fa
data/README.md CHANGED
@@ -21,10 +21,23 @@
21
21
 
22
22
  4.删除pod缓存(pod cache clean --all)
23
23
 
24
- 5.在podfile中加入plugin "cocoapods-TSPodfileTimeWatch"
24
+ 5.在podfile起始加入:
25
25
 
26
- 6.pod结束后会在pods文件夹下生成AllPodsTimeAndSize.csv文件,用来记录所有pod下载耗时情况
26
+ ```ruby
27
+ # 在这里判断是否启动插件,再加个异常保护
28
+ begin
29
+ if system "gem list | grep \"cocoapods-TSPodfileTimeWatch\""
30
+ # 判断是否有装cocoapods-TSPodfileTimeWatch插件
31
+ plugin "cocoapods-TSPodfileTimeWatch"
32
+ end
33
+ # 其他plugin...
34
+ end
35
+ ```
27
36
 
28
- 7.如果git clone文件大小和cache文件大的差值越大,说明下载的多余文件越多,则存在可优化空间。
37
+ 6.执行pod update --verbose(或者是pod install --verbose,但是一定要加--verbose,只有加了--verbose才会输出csv以及详细下载耗时信息)
29
38
 
30
- 8.可以通过尝试把podfile中使用git commit集成的,修改为使用git tag集成的方式,减少git clone下载内容
39
+ 7.pod结束后会在pods文件夹下生成AllPodsTimeAndSize.csv文件,用来记录所有pod下载耗时情况
40
+
41
+ 8.如果git clone文件大小和cache文件大的差值越大,说明下载的多余文件越多,则存在可优化空间。
42
+
43
+ 9.可以通过尝试把podfile中使用git commit集成的,修改为使用git tag集成的方式,减少git clone下载内容
@@ -1,3 +1,3 @@
1
1
  module CocoapodsTspodfiletimewatch
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -19,10 +19,20 @@ class Dir
19
19
  end
20
20
  end
21
21
  $pluginIsVerbose = false
22
+ $pluginCurrentTarget = ""
23
+ $pluginCurrentPodName = ""
24
+ $pluginCurrentZipSize = 0
25
+ $pluginCurrentZipAllSize = 0
22
26
  $gitSize = 0
23
27
  $gitAllSize = 0
24
28
  $cloneTime = 0
25
29
  $cloneAllTime = 0
30
+ $downloadTime = 0
31
+ $downloadAllTime = 0
32
+ $cdnDownloadTime = 0
33
+ $cdnDownloadAllTime = 0
34
+ $cdnUnZipTime = 0
35
+ $cdnUnZipAllTime = 0
26
36
  if ARGV.include?("--verbose")
27
37
  $pluginIsVerbose = true
28
38
  end
@@ -38,8 +48,8 @@ module CocoapodsTSPodfileTimeWatch
38
48
  File.delete("#{Dir.home}/.AllPodsTimeAndSize.csv")
39
49
  end
40
50
  # 统计到csv中
41
- CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "ab") do |csv|
42
- csv << ["名称", "下载耗时(S)", "git clone文件大小(M)", "cache文件大小(M)", "大小差值"]
51
+ CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "ab:utf-8") do |csv|
52
+ csv << ["\xEF\xBB\xBF名称", "下载耗时(S)", "下载文件大小(M)", "cache文件大小(M)", "大小差值(Git专用)", "CDN/Git", "CDN下载耗时", "CDN解压耗时"]
43
53
  end
44
54
  end
45
55
  rescue => exception
@@ -48,10 +58,14 @@ module CocoapodsTSPodfileTimeWatch
48
58
  end
49
59
  Pod::HooksManager.register("cocoapods-TSPodfileTimeWatch", :post_install) do |context|
50
60
  begin
51
- puts "\e[31mCocoapodsTSPodfileTimeWatch gitAllSize: #{$gitAllSize}M\e[0m"
52
- puts "\e[31mCocoapodsTSPodfileTimeWatch cloneAllTime: #{$cloneAllTime}S\e[0m"
61
+ puts "\e[31mCocoapodsTSPodfileTimeWatch GitCloneAllSize: #{$gitAllSize} M\e[0m"
62
+ puts "\e[31mCocoapodsTSPodfileTimeWatch GitCloneAllTime: #{$cloneAllTime} S\e[0m"
63
+ puts "\e[31mCocoapodsTSPodfileTimeWatch CDNDownloadAllSize: #{$pluginCurrentZipAllSize} M\e[0m"
64
+ puts "\e[31mCocoapodsTSPodfileTimeWatch CDNAllTime: #{$downloadAllTime} S\e[0m"
65
+ puts "\e[31mCocoapodsTSPodfileTimeWatch CDNDownloadAllTime: #{$cdnDownloadAllTime} S\e[0m"
66
+ puts "\e[31mCocoapodsTSPodfileTimeWatch CDNUnzipAllTime: #{$cdnUnZipAllTime} S\e[0m"
53
67
  # 如果是--verbose模式且$gitAllSize与$cloneAllTime(不为0表示有下载pod)
54
- if $pluginIsVerbose == true && $gitAllSize != 0 && $cloneAllTime != 0
68
+ if $pluginIsVerbose == true && $gitAllSize != 0 && $cloneAllTime != 0 && $pluginCurrentZipAllSize != 0 && $downloadAllTime != 0
55
69
  File.rename "#{Dir.home}/.AllPodsTimeAndSize.csv", "#{context.sandbox_root}/AllPodsTimeAndSize.csv"
56
70
  puts "\e[31m具体的统计数据请在#{context.sandbox_root}/AllPodsTimeAndSize.csv中查看\e[0m"
57
71
  end
@@ -79,17 +93,27 @@ module CocoapodsTSPodfileTimeWatch
79
93
  # 计算拷贝到的目录下所有文件总大小,单位为M
80
94
  dirSum = Dir.size(destination.to_s)/1000.0/1000.0
81
95
  # 标红输出cache文件大小,单位为M
82
- puts "\e[31mCocoapodsTSPodfileTimeWatch cachesize #{spec.name}: "+"#{dirSum}"+"M\e[0m"
83
- # 计算git clone大小和cache文件大小的差值,如果差值过大,则有优化空间
84
- diffSize = $gitSize - dirSum
85
- # 标红输出差值
86
- puts "\e[31mCocoapodsTSPodfileTimeWatch diffSize = #{diffSize}\e[0m"
87
- # 统计到csv中
88
- CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "a+") do |csv|
89
- csv << [spec.name, $cloneTime, $gitSize, dirSum, diffSize]
96
+ puts "\e[31mCocoapodsTSPodfileTimeWatch cachesize #{spec.name}: "+"#{dirSum}"+" M\e[0m"
97
+ # 如果相等则为CDN的下载方式
98
+ if $gitSize == 0
99
+ # CDN的下载方式
100
+ CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "a+") do |csv|
101
+ csv << [spec.name, $downloadTime, $pluginCurrentZipSize, dirSum, "CDN不统计此项", "CDN", $cdnDownloadTime, $cdnUnZipTime]
102
+ end
103
+ else
104
+ # git的下载方式
105
+ # 计算git clone大小和cache文件大小的差值,如果差值过大,则有优化空间
106
+ diffSize = $gitSize - dirSum
107
+ # 标红输出差值
108
+ puts "\e[31mCocoapodsTSPodfileTimeWatch diffSize = #{diffSize}"+"M \e[0m"
109
+ CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "a+") do |csv|
110
+ csv << [spec.name, $cloneTime, $gitSize, dirSum, diffSize, "Git", "Git不统计此项", "Git不统计此项"]
111
+ end
90
112
  end
113
+
91
114
  # 换行
92
115
  puts
116
+
93
117
  rescue => exception
94
118
  # 输出拷贝清除方法异常
95
119
  puts "\e[31mCocoapodsTSPodfileTimeWatch verboseCopy_and_clean error(已捕获): #{exception}\e[0m"
@@ -98,15 +122,23 @@ module CocoapodsTSPodfileTimeWatch
98
122
  end
99
123
  end
100
124
 
101
- class Pod::Downloader::Git
102
- # 使用方法别名hook clone方法
103
- alias :origin_clone :clone
104
- def clone(force_head = false, shallow_clone = true)
125
+
126
+ class Pod::Downloader::Cache
127
+
128
+ alias :origin_download :download
129
+
130
+ def download(request, target)
131
+ # 获取downloader下载的文件路径
132
+ source = target.to_s
133
+ # 赋值当前正在下载的文件路径给全局变量,为了解压zip的时候做判断
134
+ $pluginCurrentTarget = source
135
+ # 赋值当前正在下载的pod名称给全局变量,为了解压zip的时候做输出
136
+ $pluginCurrentPodName = request.name.to_s
105
137
  # 获取clone执行前时间点
106
138
  time1 = Time.new
107
- # 执行之前的clone方法
108
- origin_clone(force_head, shallow_clone)
109
-
139
+ # 执行之前的download_source方法,接收该方法的返回值
140
+ result, podspecs = origin_download(request, target)
141
+
110
142
  # 如果不是--verbose,只输出总耗时,总下载大小
111
143
  # 捕获一下异常,不会因为plugin的原因导致pod失败
112
144
  begin
@@ -114,39 +146,181 @@ module CocoapodsTSPodfileTimeWatch
114
146
  time2 = Time.new
115
147
  # 获取时间差
116
148
  time = time2 - time1
117
- # 赋值一个给全局变量,之后时间统计要用到
118
- $cloneTime = time
119
- # 赋值一个给全局变量,之后时间统计要用到
120
- $cloneAllTime = $cloneAllTime + time
121
- # 获取git clone下载的文件路径
122
- source = target_path.to_s
123
- # 计算git clone下载的文件大小,单位为M
124
- dirSum = Dir.size(source)/1000.0/1000.0
125
- # 赋值给一个全局变量,之后输出会用到
126
- $gitAllSize = $gitAllSize + dirSum
149
+ if request.params["git".to_sym]
150
+ # 说明是git方式
151
+ # 赋值一个给全局变量,之后时间统计要用到
152
+ $cloneTime = time
153
+ # 赋值一个给全局变量,之后时间统计要用到
154
+ $cloneAllTime = $cloneAllTime + time
155
+ # 计算downloader下载的文件大小,单位为M
156
+ dirSum = Dir.size(source)/1000.0/1000.0
157
+ # 赋值给一个全局变量,之后输出会用到
158
+ $gitAllSize = $gitAllSize + dirSum
159
+ else
160
+ # 说明是CDN方式
161
+ # 赋值一个给全局变量,之后时间统计要用到
162
+ $downloadTime = time
163
+ # 赋值一个给全局变量,之后时间统计要用到
164
+ $downloadAllTime = $downloadAllTime + time
165
+ # 赋值给一个全局变量,之后输出会用到
166
+ $cdnDownloadAllTime = $cdnDownloadAllTime + $cdnDownloadTime
167
+ # 赋值给一个全局变量,之后输出会用到
168
+ $cdnUnZipAllTime = $cdnUnZipAllTime + $cdnUnZipTime
169
+ # 赋值给一个全局变量,之后输出会用到
170
+ $pluginCurrentZipAllSize = $pluginCurrentZipAllSize + $pluginCurrentZipSize
171
+ end
172
+
127
173
  # 如果是--verbose,则输出详细信息,生成csv
128
174
  if $pluginIsVerbose == true
129
- verboseClone(force_head, shallow_clone, time, dirSum)
175
+ verboseDownload(request, time, dirSum)
130
176
  end
177
+ # 返回值
178
+ [result, podspecs]
131
179
  rescue => exception
132
180
  # 标红输出git clone hook异常
133
- puts "\e[31mCocoapodsTSPodfileTimeWatch clone error(已捕获): #{exception}\e[0m"
181
+ puts "\e[31mCocoapodsTSPodfileTimeWatch download error(已捕获): #{exception}\e[0m"
134
182
  end
183
+ end
135
184
 
185
+ def verboseDownload(request, time, dirSum)
186
+ if request.params["git".to_sym]
187
+ # 说明是git方式
188
+ # 标红输出git clone耗时
189
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} clone time: #{time}"+" S\e[0m"
190
+ # 赋值给一个全局变量,之后输出会用到
191
+ $gitSize = dirSum
192
+ # 标红输出git clone下载文件大小
193
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} clone allsize: "+"#{dirSum}"+" M\e[0m"
194
+ else
195
+ # 说明是CDN方式
196
+ # 标红输出CDN 下载耗时
197
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN download time: #{$cdnDownloadTime}"+" S\e[0m"
198
+ # 标红输出CDN 解压耗时
199
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN unzip time: #{$cdnUnZipTime}"+" S\e[0m"
200
+ # 标红输出CDN 总耗时
201
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN All time: #{$downloadTime}"+" S\e[0m"
202
+ # 标红输出CDN clone下载文件大小
203
+ puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN zipSize: "+"#{$pluginCurrentZipSize}"+" M\e[0m"
204
+ end
205
+
136
206
  end
137
207
 
138
- # --verbose输出每个库的下载耗时
139
- def verboseClone(force_head, shallow_clone, time, dirSum)
140
- # 这里只能根据url获取到pod名称的开始index
141
- start = url.rindex("/") + 1
142
- # 获取pod名称
143
- podName = url[start, url.length]
144
- # 标红输出git clone耗时
145
- puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone time: #{time}\e[0m"
146
- # 赋值给一个全局变量,之后输出会用到
147
- $gitSize = dirSum
148
- # 标红输出git clone下载文件大小
149
- puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone allsize: "+"#{dirSum}"+"M\e[0m"
208
+ end
209
+
210
+ class Pod::Downloader::Http
211
+ # 使用方法别名hook解压方法,获取解压之前的文件大小
212
+ alias :origin_download_file :download_file
213
+ alias :origin_extract_with_type :extract_with_type
214
+
215
+ def download_file(_full_filename)
216
+ # 捕获一下异常,不会因为plugin的原因导致pod失败
217
+ begin
218
+ if _full_filename.to_s.include?($pluginCurrentTarget)
219
+ # 说明是之前被赋值的开始下载了
220
+
221
+ # 获取CDN下载执行前时间点
222
+ time1 = Time.new
223
+ # 执行原来的CDN下载方法
224
+ origin_download_file(_full_filename)
225
+ # 获取CDN下载执行后时间点
226
+ time2 = Time.new
227
+ # 赋值CDN下载耗时给全局变量,用于之后输出以及写在csv中
228
+ $cdnDownloadTime = time2 - time1
229
+ else
230
+ # 说明不是之前被赋值的开始下载了,输出一下,然后清空
231
+ puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentTarget} target error\e[0m"
232
+ puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentPodName} name error\e[0m"
233
+ $pluginCurrentTarget = ""
234
+ $pluginCurrentPodName = ""
235
+ end
236
+ rescue => exception
237
+ # 输出CDM下载方法异常
238
+ puts "\e[31mCocoapodsTSPodfileTimeWatch download_file error(已捕获): #{exception}\e[0m"
239
+ end
240
+
241
+ end
242
+
243
+ def extract_with_type(full_filename, type = :zip)
244
+ # 捕获一下异常,不会因为plugin的原因导致pod失败
245
+ begin
246
+ if full_filename.to_s.include?($pluginCurrentTarget)
247
+ # 说明是之前被赋值的下载完成了,开始进行解压了
248
+
249
+ # 计算拷贝到的目录下所有文件总大小,单位为M
250
+ dirSum = File.size(full_filename.to_s)/1000.0/1000.0
251
+ # 赋值给当前正在解压的zip大小,之后输出到csv要用
252
+ $pluginCurrentZipSize = dirSum
253
+ else
254
+ # 说明不是之前被赋值的下载完成了,输出一下,然后清空
255
+ puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentTarget} target error\e[0m"
256
+ puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentPodName} name error\e[0m"
257
+ $pluginCurrentTarget = ""
258
+ $pluginCurrentPodName = ""
259
+ end
260
+ rescue => exception
261
+ # 输出CDN解压方法异常
262
+ puts "\e[31mCocoapodsTSPodfileTimeWatch extract_with_type error(已捕获): #{exception}\e[0m"
263
+ end
264
+ # 获取CDN解压前时间点
265
+ time1 = Time.new
266
+ # 执行之前的解压方法
267
+ origin_extract_with_type(full_filename, type)
268
+ # 获取CDN解压后时间点
269
+ time2 = Time.new
270
+ # 赋值CDN解压耗时给全局变量,用于之后输出以及写在csv中
271
+ $cdnUnZipTime = time2 - time1
150
272
  end
151
273
  end
274
+
275
+ # class Pod::Downloader::Git
276
+ # # 使用方法别名hook clone方法
277
+ # alias :origin_clone :clone
278
+ # def clone(force_head = false, shallow_clone = true)
279
+ # # 获取clone执行前时间点
280
+ # time1 = Time.new
281
+ # # 执行之前的clone方法
282
+ # origin_clone(force_head, shallow_clone)
283
+
284
+ # # 如果不是--verbose,只输出总耗时,总下载大小
285
+ # # 捕获一下异常,不会因为plugin的原因导致pod失败
286
+ # begin
287
+ # # 获取clone执行后时间点
288
+ # time2 = Time.new
289
+ # # 获取时间差
290
+ # time = time2 - time1
291
+ # # 赋值一个给全局变量,之后时间统计要用到
292
+ # $cloneTime = time
293
+ # # 赋值一个给全局变量,之后时间统计要用到
294
+ # $cloneAllTime = $cloneAllTime + time
295
+ # # 获取git clone下载的文件路径
296
+ # source = target_path.to_s
297
+ # # 计算git clone下载的文件大小,单位为M
298
+ # dirSum = Dir.size(source)/1000.0/1000.0
299
+ # # 赋值给一个全局变量,之后输出会用到
300
+ # $gitAllSize = $gitAllSize + dirSum
301
+ # # 如果是--verbose,则输出详细信息,生成csv
302
+ # if $pluginIsVerbose == true
303
+ # verboseClone(force_head, shallow_clone, time, dirSum)
304
+ # end
305
+ # rescue => exception
306
+ # # 标红输出git clone hook异常
307
+ # puts "\e[31mCocoapodsTSPodfileTimeWatch clone error(已捕获): #{exception}\e[0m"
308
+ # end
309
+
310
+ # end
311
+
312
+ # # --verbose输出每个库的下载耗时
313
+ # def verboseClone(force_head, shallow_clone, time, dirSum)
314
+ # # 这里只能根据url获取到pod名称的开始index
315
+ # start = url.rindex("/") + 1
316
+ # # 获取pod名称
317
+ # podName = url[start, url.length]
318
+ # # 标红输出git clone耗时
319
+ # puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone time: #{time}\e[0m"
320
+ # # 赋值给一个全局变量,之后输出会用到
321
+ # $gitSize = dirSum
322
+ # # 标红输出git clone下载文件大小
323
+ # puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone allsize: "+"#{dirSum}"+"M\e[0m"
324
+ # end
325
+ # end
152
326
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-TSPodfileTimeWatch
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
  - keai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler