cocoapods-dev-env 0.9.5 → 2.0.1

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: fd68a372c6dd4a725b88b5a9ec980e74dc08cf8a20f4548c04e5d339dbacec41
4
- data.tar.gz: bf1e33191942fc5b085681fe39a943a99f6518ea052bf96e71b970d22bb637b0
3
+ metadata.gz: 3afe919528275cf8b10ba4dc9f641fb314d41973a20b3af3a04f4eb7d6b2490f
4
+ data.tar.gz: 89636fb4ea8ac5450f61b682a1e472bfaa2265d3488240c674135baa2bbcf78b
5
5
  SHA512:
6
- metadata.gz: 2a711c3ca0d7bc6beee77bae2b6b2255b43f642de3aebe33a4c8f4c253f28c33c2c240e751e81f87603111b389fd93cb83218d551963a35e8931da97e4bbdf60
7
- data.tar.gz: c98b59b570d976f4486c3e0bb5e53562cffbdacab07a10cf6de123415babbd71d1c35fce79ffe4285fedcedfbf5704d4ca914da904d63d57d8b4bf20441a69d1
6
+ metadata.gz: 88e9376cedc8fbee56febc9339c05f032bd7dba76793fba50145aa7f612af8f60331b8c523018c922d71c0083e5167e2220b6bf92b3f3c84b2c664343d591519
7
+ data.tar.gz: d32ccb577e9f11f1d935f12009ba6c60db7f6c4aef447ffe730f310afb20ed82e63aa858fe6157d318bf9b8e3c96fad7655093fdf9207e583101a9a3bafaeda2
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ vendor/
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cocoapods-dev-env (2.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 2.0)
16
+ cocoapods-dev-env!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 2.1.4
data/README.md CHANGED
@@ -53,6 +53,21 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
53
53
 
54
54
  Bug reports and pull requests are welcome on GitHub at https://github.com/YoudaoMobile/cocoapods-dev-env. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
55
 
56
+ ### prepare
57
+ install gem bundler:
58
+
59
+ gem install bundler
60
+
61
+ create Gemfile:
62
+
63
+ bundler init
64
+
65
+ edit GemFile for local path, e.g.:
66
+
67
+ gem 'cocoapods'
68
+ gem 'cocoapods-dev-env', :path => '../cocoapods-dev-env'
69
+
70
+ ### debug and package
56
71
  1. How to develop: put gem in your project and exec `bundle exec pod install`
57
72
  2. How to packagae: `rake build`
58
73
  3. How to release: `rake release` or `gem push ./pkg/cocoapods-dev-env-0.2.2.gem`
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
+ spec.add_dependency 'luna-binary-uploader'
31
32
  spec.add_development_dependency "bundler", "~> 2.0"
32
33
  spec.add_development_dependency "rake", "~> 10.0"
33
34
  end
@@ -1,7 +1,7 @@
1
1
  module Cocoapods
2
2
  module Dev
3
3
  module Env
4
- VERSION = "0.9.5"
4
+ VERSION = "2.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,6 @@
1
+ require "file_processer"
2
+ require "luna-binary-uploader"
3
+
1
4
  Pod::HooksManager.register('cocoapods-dev-env', :pre_install) do |installer|
2
5
  podfile = installer.podfile
3
6
  #puts installer.instance_variables
@@ -21,13 +24,17 @@ module Pod
21
24
  def self.keyword
22
25
  :dev_env # 'dev'/'beta'/'release'
23
26
  end
27
+ def self.binary_key
28
+ :dev_env_use_binary # true / false
29
+ end
24
30
  UI.message "🎉 plugin cocoapods-dev-env loaded 🎉".green
25
31
  end
26
32
  class Podfile
27
33
  class TargetDefinition
34
+ attr_reader :binary_repo_url
28
35
 
29
36
  def searchAndOpenLocalExample(path)
30
- currentDir = Dir.pwd
37
+ _currentDir = Dir.pwd
31
38
  Dir.chdir(path)
32
39
  Dir.chdir("Example")
33
40
  `pod install`
@@ -36,11 +43,11 @@ class Podfile
36
43
  `open -a Terminal ./`
37
44
  `open #{projPaths[0]}`
38
45
  end
39
- Dir.chdir(currentDir)
46
+ Dir.chdir(_currentDir)
40
47
  end
41
48
 
42
49
  def checkAndRemoveSubmodule(path)
43
- currentDir = Dir.pwd
50
+ _currentDir = Dir.pwd
44
51
  Dir.chdir(path)
45
52
  output = `git status -s`
46
53
  puts output
@@ -52,7 +59,7 @@ class Podfile
52
59
  else
53
60
  raise "submodule #{path} 移除失败,有未提交的修改"
54
61
  end
55
- Dir.chdir(currentDir)
62
+ Dir.chdir(_currentDir)
56
63
  `
57
64
  git submodule deinit #{path}
58
65
  rm -rf #{path}
@@ -61,10 +68,10 @@ class Podfile
61
68
  end
62
69
 
63
70
  def checkTagIsEqualToHead(tag, path)
64
- currentDir = Dir.pwd
71
+ _currentDir = Dir.pwd
65
72
  Dir.chdir(path)
66
73
  result = `git describe --abbrev=4 HEAD`
67
- Dir.chdir(currentDir)
74
+ Dir.chdir(_currentDir)
68
75
  if result.include?(tag)
69
76
  return true
70
77
  else
@@ -74,12 +81,12 @@ class Podfile
74
81
 
75
82
  # 这个函数有问题有时候拿不到相同的commit id
76
83
  def checkTagOrBranchIsEqalToHead(branchOrTag, path)
77
- currentDir = Dir.pwd
84
+ _currentDir = Dir.pwd
78
85
  Dir.chdir(path)
79
86
  headCommitID = `git rev-parse HEAD`
80
87
  tagCommitID = `git rev-parse #{branchOrTag}`
81
88
  UI.puts "#{`pwd`} headCommitID:#{headCommitID} \n #{branchOrTag}ComitID:#{tagCommitID}"
82
- Dir.chdir(currentDir)
89
+ Dir.chdir(_currentDir)
83
90
  return (headCommitID.length > 0 && headCommitID == tagCommitID)
84
91
  end
85
92
 
@@ -99,6 +106,12 @@ class Podfile
99
106
  end
100
107
  end
101
108
 
109
+ def checkRemoteTagExist(tag)
110
+ `git push --tags`
111
+ ret = system("git ls-remote --exit-code origin refs/tags/#{tag}")
112
+ return ret
113
+ end
114
+
102
115
  def addGitTagAndPush(tag, pod_name)
103
116
  ret = system("git tag #{tag}")
104
117
  if ret == true
@@ -153,13 +166,29 @@ class Podfile
153
166
  index = STDIN.gets.to_i - 1
154
167
  end until (index >= 0 && index < podfile.sources.size)
155
168
  source = podfile.sources[index]
169
+ UI.puts "#{"选择了发布到: ".yellow}. #{source.green}(#{index + 1})"
156
170
  return source
157
171
  end
158
172
 
173
+ def changeVersionInCocoapods(name, newVersion)
174
+ if (newVersion == nil)
175
+ UI.puts "💔 切换版本号的版本现在为空,无法设置版本号".yellow
176
+ return
177
+ end
178
+ specName = name + ".podspec"
179
+ FileProcesserManager.new(specName,
180
+ [
181
+ FileProcesser.new(-> (fileContent) {
182
+ return fileContent.gsub(/(\.version *= *')(.*')/, "\\1" + newVersion + "'")
183
+ })
184
+ ]).process()
185
+ `git add #{specName}
186
+ git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
187
+ end
188
+
159
189
  ## --- option for setting using prebuild framework ---
190
+
160
191
  def parse_pod_dev_env(name, requirements)
161
-
162
-
163
192
  options = requirements.last
164
193
  pod_name = Specification.root_name(name)
165
194
  last_options = $processedPodsOptions[pod_name]
@@ -171,137 +200,238 @@ class Podfile
171
200
  else
172
201
  requirements.push(last_options)
173
202
  end
174
-
175
- return
176
- end
177
- if options.is_a?(Hash)
203
+ elsif options.is_a?(Hash)
204
+ use_binary = options.delete(Pod::DevEnv::binary_key)
178
205
  dev_env = options.delete(Pod::DevEnv::keyword)
179
- if dev_env == nil
180
- return
181
- end
182
- UI.message "pod #{name.green} dev-env: #{dev_env.green}"
183
- git = options.delete(:git)
184
- branch = options.delete(:branch)
185
- tag = options.delete(:tag)
186
- path = options.delete(:path)
187
- if path == nil
188
- path = "./developing_pods/#{pod_name}"
206
+
207
+ deal_dev_env_with_options(dev_env, options, pod_name, name, requirements)
208
+ if dev_env != 'dev'
209
+ useBinary(dev_env, pod_name, use_binary, options, requirements)
189
210
  end
190
- if git == nil || git.length == 0
191
- raise "💔 #{pod_name.yellow} 未定义:git => 'xxx'库地址"
211
+
212
+
213
+ if dev_env || use_binary
214
+ $processedPodsOptions[pod_name] = options.clone
215
+ requirements.pop if options.empty?
192
216
  end
193
- if branch == nil || branch.length == 0
194
- raise "💔 #{pod_name.yellow} 未定义:branch => 'xxx'"
217
+ end
218
+ end
219
+
220
+ def deal_dev_env_with_options(dev_env, options, pod_name, name, requirements)
221
+ if dev_env == nil
222
+ return
223
+ end
224
+ UI.message "pod #{name.green} dev-env: #{dev_env.green}"
225
+ git = options.delete(:git)
226
+ branch = options.delete(:branch)
227
+ tag = options.delete(:tag)
228
+ path = options.delete(:path)
229
+ if path == nil
230
+ path = "./developing_pods/#{pod_name}"
231
+ end
232
+ if git == nil || git.length == 0
233
+ raise "💔 #{pod_name.yellow} 未定义:git => 'xxx'库地址"
234
+ end
235
+ if branch == nil || branch.length == 0
236
+ raise "💔 #{pod_name.yellow} 未定义:branch => 'xxx'"
237
+ end
238
+ if tag == nil || tag.length == 0
239
+ raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
240
+ end
241
+
242
+ if dev_env == 'subtree'
243
+ if !File.directory?(path)
244
+ _toplevelDir = `git rev-parse --show-toplevel`
245
+ _currentDir = `pwd`
246
+ _subtreeDir = path
247
+ if _currentDir != _toplevelDir
248
+ Dir.chdir(_toplevelDir)
249
+ _end = path
250
+ if _end[0,2] == './'
251
+ _end = _end[1, _end.length - 1]
252
+ else
253
+ _end = '/' + _end
254
+ end
255
+ _subtreeDir = './' + _currentDir[_toplevelDir.length, _currentDir.length - _toplevelDir.length] + path
256
+ end
257
+ _cmd = "git subtree add --prefix #{_subtreeDir} #{git} #{branch} --squash"
258
+ UI.puts _cmd
259
+ system(_cmd)
260
+ Dir.chdir(_currentDir)
195
261
  end
196
- if tag == nil || tag.length == 0
197
- raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
262
+ options[:path] = path
263
+ if requirements.length >= 2
264
+ requirements.delete_at(0)
198
265
  end
266
+ UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
267
+ elsif dev_env == 'dev'
268
+ # 开发模式,使用path方式引用本地的submodule git库
269
+ if !File.directory?(path)
270
+ UI.puts "add submodule for #{pod_name.green}".yellow
271
+ _cmd = "git submodule add --force -b #{branch} #{git} #{path}"
272
+ UI.puts _cmd
273
+ system(_cmd)
274
+
275
+ _currentDir = Dir.pwd
276
+ Dir.chdir(path)
199
277
 
200
- if dev_env == 'subtree'
201
- options[:path] = path
202
- if requirements.length >= 2
203
- requirements.delete_at(0)
278
+ curGitRemoteUrl = `git remote get-url origin`.rstrip()
279
+ if curGitRemoteUrl == git
280
+ _cmd = "git reset --hard"
281
+ UI.puts _cmd
282
+ system(_cmd)
204
283
  end
205
- UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
206
- elsif dev_env == 'dev'
207
- # 开发模式,使用path方式引用本地的submodule git库
208
- if !File.directory?(path)
209
- UI.puts "add submodule for #{pod_name.green}".yellow
210
- # TODO 这个命令要想办法展示实际报错信息
211
- `git submodule add --force -b #{branch} #{git} #{path}`
212
- # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
213
- # searchAndOpenLocalExample(path)
214
- # end
215
- if !checkTagIsEqualToHead(tag, path) && !checkTagIsEqualToHead("#{tag}_beta", path)
216
- raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
284
+ Dir.chdir(_currentDir)
285
+
286
+ # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
287
+ # searchAndOpenLocalExample(path)
288
+ # end
289
+ if !checkTagIsEqualToHead(tag, path) && !checkTagIsEqualToHead("#{tag}_beta", path)
290
+ raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
291
+ end
292
+ else
293
+ # if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
294
+ # searchAndOpenLocalExample(path)
295
+ # end
296
+ end
297
+ options[:path] = path
298
+ if requirements.length >= 2
299
+ requirements.delete_at(0)
300
+ end
301
+ UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
302
+ elsif dev_env == 'beta'
303
+ # Beta模式,使用tag引用远端git库的代码
304
+ originTag = tag
305
+ tag = "#{tag}_beta"
306
+ if File.directory?(path)
307
+ # 从Dev模式刚刚切换过来,需要打tag并且push
308
+ UI.puts "release beta-version for #{pod_name.green}".yellow
309
+ _currentDir = Dir.pwd
310
+ Dir.chdir(path)
311
+ # 已经进入到podspec的文件夹中了
312
+ checkGitStatusAndPush(pod_name) # push一下
313
+ ret = checkRemoteTagExist(tag)
314
+ if ret == true
315
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
316
+ if checkTagOrBranchIsEqalToHead(tag, "./")
317
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag"
318
+ else
319
+ if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
320
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
321
+ end
217
322
  end
218
323
  else
219
- # if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
220
- # searchAndOpenLocalExample(path)
221
- # end
324
+ # tag不存在,
325
+ changeVersionInCocoapods(pod_name, originTag)
326
+ checkGitStatusAndPush(pod_name) # 再push一下
327
+ addGitTagAndPush(tag, pod_name)
222
328
  end
223
- options[:path] = path
224
- if requirements.length >= 2
225
- requirements.delete_at(0)
329
+ Dir.chdir(_currentDir)
330
+ checkAndRemoveSubmodule(path)
331
+ end
332
+ options[:git] = git
333
+ options[:tag] = tag
334
+ if requirements.length >= 2
335
+ requirements.delete_at(0)
336
+ end
337
+ UI.message "enabled #{"beta".green}-mode for #{pod_name.green}"
338
+ elsif dev_env == 'release'
339
+ # Release模式,直接使用远端对应的版本
340
+ if File.directory?(path)
341
+ UI.puts "release release-version for #{pod_name.green}".yellow
342
+ _currentDir = Dir.pwd
343
+ Dir.chdir(path)
344
+ verboseParamStr = ""
345
+ if Config.instance.verbose
346
+ verboseParamStr = " --verbose"
226
347
  end
227
- UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
228
- elsif dev_env == 'beta'
229
- # Beta模式,使用tag引用远端git库的代码
230
- tag = "#{tag}_beta"
231
- if File.directory?(path)
232
- # 从Dev模式刚刚切换过来,需要打tag并且push
233
- UI.puts "release beta-version for #{pod_name.green}".yellow
234
- currentDir = Dir.pwd
235
- Dir.chdir(path)
236
- checkGitStatusAndPush(pod_name)
237
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
238
- ret = addGitTagAndPush(tag, pod_name)
239
- if ret != true
240
- if checkTagOrBranchIsEqalToHead(tag, "./")
241
- UI.puts "#{pod_name.green} 没做任何调整,切换回beta"
242
- else
243
- if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
244
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
245
- end
246
- end
348
+ ret = system("pod lib lint --skip-import-validation --fail-fast --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
349
+ if ret != true
350
+ raise "💔 #{pod_name.yellow} lint 失败"
351
+ end
352
+ checkGitStatusAndPush(pod_name)
353
+ changeVersionInCocoapods(pod_name, tag)
354
+ checkGitStatusAndPush(pod_name)
355
+ ret = addGitTagAndPush(tag, pod_name)
356
+ if ret == false
357
+ if checkTagOrBranchIsEqalToHead(tag, "./")
358
+ UI.puts "#{pod_name.green} 已经打过tag".yellow
359
+ else
360
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
247
361
  end
248
- Dir.chdir(currentDir)
249
- checkAndRemoveSubmodule(path)
250
362
  end
251
- options[:git] = git
252
- options[:tag] = tag
253
- if requirements.length >= 2
254
- requirements.delete_at(0)
363
+ ## TODO:: 发布到的目标库名称需要用变量设置
364
+ repoAddrs = getUserRepoAddress()
365
+ cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings --use-modular-headers#{getReposStrForLint()}#{verboseParamStr}"
366
+ UI.puts cmd.green
367
+ ret = system(cmd)
368
+ if ret != true
369
+ raise "💔 #{pod_name.yellow} 发布失败"
255
370
  end
256
- UI.message "enabled #{"beta".green}-mode for #{pod_name.green}"
257
- elsif dev_env == 'release'
258
- # Release模式,直接使用远端对应的版本
259
- if File.directory?(path)
260
- UI.puts "release release-version for #{pod_name.green}".yellow
261
- currentDir = Dir.pwd
262
- Dir.chdir(path)
263
- verboseParamStr = ""
264
- if Config.instance.verbose
265
- verboseParamStr = " --verbose"
266
- end
267
- ret = system("pod lib lint --skip-import-validation --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
268
- if ret != true
269
- raise "💔 #{pod_name.yellow} lint 失败"
270
- end
271
- checkGitStatusAndPush(pod_name)
272
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
273
- ret = addGitTagAndPush(tag, pod_name)
274
- if ret == false
275
- if checkTagOrBranchIsEqalToHead(tag, "./")
276
- UI.puts "#{pod_name.green} 已经打过tag".yellow
371
+ ## 到最后统一执行,判断如果当次release过
372
+ `pod repo update`
373
+ Dir.chdir(_currentDir)
374
+ checkAndRemoveSubmodule(path)
375
+ end
376
+ if requirements.length < 2
377
+ requirements.insert(0, "#{tag}")
378
+ end
379
+ UI.message "enabled #{"release".green}-mode for #{pod_name.green}"
380
+ else
381
+ raise "💔 :dev_env 必须要设置成 dev/beta/release之一,不接受其他值"
382
+ end
383
+ end
384
+
385
+ def useBinary(dev_env, pod_name, use_binary, options, requirements)
386
+ if use_binary && use_binary == true
387
+ options.delete(:git)
388
+ options.delete(:tag)
389
+ options.delete(:path)
390
+ options[:source] = binary_repo_url
391
+ else
392
+ if options[:source] == nil
393
+ begin
394
+ sources = find_pod_repos(pod_name).sources.select{|item| item.url.downcase != binary_repo_url.downcase } if options.empty?
395
+ if sources != nil
396
+ if sources.length >= 2
397
+ p "#{pod_name} 有多个source #{sources}"
398
+ source_url = sources.detect{|item| item.url.downcase != Pod::TrunkSource::TRUNK_REPO_URL.downcase && item.url.downcase != "https://github.com/CocoaPods/Specs.git".downcase}.url
277
399
  else
278
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
400
+ source_url = sources.first.url
279
401
  end
280
402
  end
281
- ## TODO:: 发布到的目标库名称需要用变量设置
282
- repoAddrs = getUserRepoAddress()
283
- cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings#{getReposStrForLint()}"
284
- UI.puts cmd.green
285
- ret = system(cmd)
286
- if ret != true
287
- raise "💔 #{pod_name.yellow} 发布失败"
288
- end
289
- ## 到最后统一执行,判断如果当次release过
290
- `pod repo update`
291
- Dir.chdir(currentDir)
292
- checkAndRemoveSubmodule(path)
293
- end
294
- if requirements.length < 2
295
- requirements.insert(0, "#{tag}")
403
+ options[:source] = source_url if source_url != nil
404
+ UI.puts "#{pod_name} :source=> #{options[:source]} by cocoapods-dev-env".yellow if options[:source] != nil
405
+
406
+ rescue => exception
407
+ UI.puts "#{pod_name} exception:#{exception}".red
408
+ else
409
+
296
410
  end
297
- UI.message "enabled #{"release".green}-mode for #{pod_name.green}"
298
- else
299
- raise "💔 :dev_env 必须要设置成 dev/beta/release之一,不接受其他值"
300
411
  end
301
- $processedPodsOptions[pod_name] = options
302
- requirements.pop if options.empty?
303
412
  end
304
413
  end
414
+
415
+ def binary_repo_url
416
+ if @binary_repo_url == nil
417
+ @binary_repo_url = Luna::Binary::Common.instance.binary_repo_url #从luna-binary-uploader里获取binary_repo_url
418
+ end
419
+ return @binary_repo_url
420
+ end
421
+
422
+ def find_pod_repos(pod_name) #等同pod search
423
+ sets = Pod::Config.instance.sources_manager.search_by_name(pod_name)
424
+ if sets.count == 1
425
+ set = sets.first
426
+ elsif sets.map(&:name).include?(pod_name)
427
+ set = sets.find { |s| s.name == pod_name }
428
+ else
429
+ names = sets.map(&:name) * ', '
430
+ raise Informative, "More than one spec found for '#{pod_name}':\n#{names}"
431
+ end
432
+ return set
433
+ end
434
+
305
435
  # ---- patch method ----
306
436
  # We want modify `store_pod` method, but it's hard to insert a line in the
307
437
  # implementation. So we patch a method called in `store_pod`.
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $LOAD_PATH << '.'
4
+
5
+ class YDFileUtils
6
+ def self.writeFile (filePath, buffer)
7
+ File.open(filePath, "w") { |source_file|
8
+ source_file.write buffer
9
+ }
10
+ return
11
+ end
12
+ end
13
+
14
+ class FileProcesserInterface
15
+ def process(filePath)
16
+ puts filePath
17
+ end
18
+ end
19
+
20
+ class FileProcesser < FileProcesserInterface
21
+ def initialize(processFunc)
22
+ @processFunc = processFunc
23
+ end
24
+
25
+ def process(filePath)
26
+ fileContent = File.read(filePath)
27
+ result = @processFunc.call(fileContent)
28
+ File.write(filePath, result)
29
+ end
30
+ end
31
+
32
+ class RegexFileProcesser < FileProcesserInterface
33
+
34
+ def initialize(regex, genLineFunc)
35
+ @regex = regex
36
+ @genLineFunc = genLineFunc
37
+ end
38
+
39
+ def process(filePath)
40
+ buffer = ""
41
+ IO.foreach(filePath) { |line|
42
+ current_number_regex = line =~ @regex
43
+ if current_number_regex
44
+ regexCatchedValue = $~
45
+ buffer += line.gsub(@regex, @genLineFunc.call(regexCatchedValue))
46
+ else
47
+ buffer += line
48
+ end
49
+ }
50
+ YDFileUtils.writeFile(filePath, buffer)
51
+ end
52
+ end
53
+
54
+
55
+
56
+ class FileProcesserManager
57
+
58
+ def initialize(files, fileProcesserList)
59
+ @files = files
60
+ @fileProcesserList = fileProcesserList
61
+ end
62
+
63
+ private def getFiles()
64
+ mappingFiles = Dir::glob(@files)
65
+ return mappingFiles
66
+ end
67
+
68
+ private def processFile(filePath)
69
+ @fileProcesserList.each { |processer|
70
+ processer.process(filePath)
71
+ }
72
+ end
73
+
74
+ public def process()
75
+ ocFiles = getFiles()
76
+ puts "共发现 #{ocFiles.count} 个文件可能需要替换"
77
+
78
+ @@count = 0
79
+ ocFiles.each do |filePath|
80
+ processFile(filePath)
81
+ end
82
+ end
83
+ end
84
+
85
+ ##### 最简调用示例
86
+ # FileProcesserManager.new("../**/*.{m,mm}", [FileProcesserInterface.new()]).process()
87
+
88
+ #### 通过 RegexFileProcesser 处理文件
89
+ # FileProcesserManager.new("../YoudaoDict/Vendor/SwipeView/SwipeView.m",
90
+ # [
91
+ # RegexFileProcesser.new(/SwipeView/, -> (regexCatchedValue) {
92
+ # return "#{regexCatchedValue.to_s}aaa"
93
+ # })
94
+ # ]).process()
95
+
96
+ #### 通过gsub处理文件
97
+ # FileProcesserManager.new("../YoudaoDict/Vendor/SwipeView/SwipeView.m",
98
+ # [
99
+ # FileProcesser.new(-> (fileContent) {
100
+ # fileContent.gsub(/(SwipeView)/, "aaa\\1")
101
+ # })
102
+ # ]).process()
103
+
104
+ # FileProcesserManager.new("../YoudaoDict/Vendor/SwipeView/SwipeView.m",
105
+ # [
106
+ # FileProcesser.new(-> (fileContent) {
107
+ # fileContent.gsub(/(SwipeView)/) do |ste|
108
+ # "#{$1} use gsub block"
109
+ # end
110
+ # })
111
+ # ]).process()
112
+
113
+
114
+ #FileProcesserManager.new("../YoudaoDict/Application/UIColor+HEXStringToColor.m",
115
+ # [
116
+ # FileProcesser.new(-> (fileContent) {
117
+ # fileContent.gsub(/([self commonHEXStringToColor:@")0xF73944("])/) do |ste|
118
+ # "#{$1} use gsub block"
119
+ # end
120
+ # })
121
+ #]).process()
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-dev-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 吴锡苗
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: luna-binary-uploader
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,6 +62,7 @@ files:
48
62
  - ".gitignore"
49
63
  - CODE_OF_CONDUCT.md
50
64
  - Gemfile
65
+ - Gemfile.lock
51
66
  - LICENSE.txt
52
67
  - README.md
53
68
  - Rakefile
@@ -57,6 +72,7 @@ files:
57
72
  - lib/cocoapods/dev/env.rb
58
73
  - lib/cocoapods/dev/env/version.rb
59
74
  - lib/cocoapods_plugin.rb
75
+ - lib/file_processer.rb
60
76
  homepage: https://github.com/YoudaoMobile/cocoapods-dev-env
61
77
  licenses:
62
78
  - MIT