cocoapods-dev-env 0.9.3 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79849534fe222e0870f9b6ee0251c66a7f1a2735c1b53f9ece362b84d75de0bb
4
- data.tar.gz: cefa85fd2097475b0a0af4714cea561dc2374854add5cc9c996c030666806366
3
+ metadata.gz: 5d24f5687a5869c6b2a4b22a0e105c6aae21bc9bfcdc8a3eb502b6b1b3234cc4
4
+ data.tar.gz: c6c18b0fe87691bcb8d02c2797a5699c720fd5826dd9c0ea6aab5af9b4c652f3
5
5
  SHA512:
6
- metadata.gz: d29362439894d87b5baf8331cbe4859ac8f8f98081fe1266fbe4c4aa66f3bbd8db4a9d63e3095f521477524186084f30bff5cedb082c3cd902a1a474177a2607
7
- data.tar.gz: ab6b0004169679ae583ea2efd4d69ef35ea8523d9d376d5df20add84143f790968c07b6d7e9570d527e9c8e87db40858a620c18064e7eed5e2b1b69bb86da089
6
+ metadata.gz: f067f655efe01bfe0feb2d8f17b64ee783f0389138ce1c59dfd605be402937fb116fa90ceb67b494594f081605c3fe57d5fb2e526ba63b597fe6d7a511bea636
7
+ data.tar.gz: b31c7e4d5ed3af8bd3c58b3439665a237d9e6e654197108ab3b740a41f4bffdbd7fd8503d229b8db6eda304e32d74e25657ea666d65c43f9bab108d2ab78a6de
data/README.md CHANGED
@@ -41,7 +41,6 @@ Finally the state clean submodule will be removed automatically.
41
41
 
42
42
  3. When you define "dev_env" to "release", and run ```pod install``` .
43
43
  We want to use the release version in cocoapods repo. And do many check for state, and help you to release the not released pod.
44
- **But we hav't done it.**
45
44
 
46
45
 
47
46
  ## Development
@@ -54,6 +53,21 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
54
53
 
55
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.
56
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
57
71
  1. How to develop: put gem in your project and exec `bundle exec pod install`
58
72
  2. How to packagae: `rake build`
59
73
  3. How to release: `rake release` or `gem push ./pkg/cocoapods-dev-env-0.2.2.gem`
@@ -1,7 +1,7 @@
1
1
  module Cocoapods
2
2
  module Dev
3
3
  module Env
4
- VERSION = "0.9.3"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,5 @@
1
+ require "file_processer"
2
+
1
3
  Pod::HooksManager.register('cocoapods-dev-env', :pre_install) do |installer|
2
4
  podfile = installer.podfile
3
5
  #puts installer.instance_variables
@@ -27,7 +29,7 @@ class Podfile
27
29
  class TargetDefinition
28
30
 
29
31
  def searchAndOpenLocalExample(path)
30
- currentDir = Dir.pwd
32
+ _currentDir = Dir.pwd
31
33
  Dir.chdir(path)
32
34
  Dir.chdir("Example")
33
35
  `pod install`
@@ -36,11 +38,11 @@ class Podfile
36
38
  `open -a Terminal ./`
37
39
  `open #{projPaths[0]}`
38
40
  end
39
- Dir.chdir(currentDir)
41
+ Dir.chdir(_currentDir)
40
42
  end
41
43
 
42
44
  def checkAndRemoveSubmodule(path)
43
- currentDir = Dir.pwd
45
+ _currentDir = Dir.pwd
44
46
  Dir.chdir(path)
45
47
  output = `git status -s`
46
48
  puts output
@@ -52,7 +54,7 @@ class Podfile
52
54
  else
53
55
  raise "submodule #{path} 移除失败,有未提交的修改"
54
56
  end
55
- Dir.chdir(currentDir)
57
+ Dir.chdir(_currentDir)
56
58
  `
57
59
  git submodule deinit #{path}
58
60
  rm -rf #{path}
@@ -61,10 +63,10 @@ class Podfile
61
63
  end
62
64
 
63
65
  def checkTagIsEqualToHead(tag, path)
64
- currentDir = Dir.pwd
66
+ _currentDir = Dir.pwd
65
67
  Dir.chdir(path)
66
68
  result = `git describe --abbrev=4 HEAD`
67
- Dir.chdir(currentDir)
69
+ Dir.chdir(_currentDir)
68
70
  if result.include?(tag)
69
71
  return true
70
72
  else
@@ -74,12 +76,12 @@ class Podfile
74
76
 
75
77
  # 这个函数有问题有时候拿不到相同的commit id
76
78
  def checkTagOrBranchIsEqalToHead(branchOrTag, path)
77
- currentDir = Dir.pwd
79
+ _currentDir = Dir.pwd
78
80
  Dir.chdir(path)
79
81
  headCommitID = `git rev-parse HEAD`
80
82
  tagCommitID = `git rev-parse #{branchOrTag}`
81
83
  UI.puts "#{`pwd`} headCommitID:#{headCommitID} \n #{branchOrTag}ComitID:#{tagCommitID}"
82
- Dir.chdir(currentDir)
84
+ Dir.chdir(_currentDir)
83
85
  return (headCommitID.length > 0 && headCommitID == tagCommitID)
84
86
  end
85
87
 
@@ -99,6 +101,12 @@ class Podfile
99
101
  end
100
102
  end
101
103
 
104
+ def checkRemoteTagExist(tag)
105
+ `git push --tags`
106
+ ret = system("git ls-remote --exit-code origin refs/tags/#{tag}")
107
+ return ret
108
+ end
109
+
102
110
  def addGitTagAndPush(tag, pod_name)
103
111
  ret = system("git tag #{tag}")
104
112
  if ret == true
@@ -111,6 +119,10 @@ class Podfile
111
119
  end
112
120
 
113
121
  def inputNeedJumpForReson(str)
122
+ if ARGV.include? '--silent'
123
+ return false
124
+ end
125
+
114
126
  puts str.green
115
127
  puts '是(Y), 任意其他输入或直接回车跳过'.green
116
128
  input = STDIN.gets
@@ -149,24 +161,32 @@ class Podfile
149
161
  index = STDIN.gets.to_i - 1
150
162
  end until (index >= 0 && index < podfile.sources.size)
151
163
  source = podfile.sources[index]
164
+ UI.puts "#{"选择了发布到: ".yellow}. #{source.green}(#{index + 1})"
152
165
  return source
153
166
  end
154
167
 
168
+ def changeVersionInCocoapods(name, newVersion)
169
+ if (newVersion == nil)
170
+ UI.puts "💔 切换版本号的版本现在为空,无法设置版本号".yellow
171
+ return
172
+ end
173
+ specName = name + ".podspec"
174
+ FileProcesserManager.new(specName,
175
+ [
176
+ FileProcesser.new(-> (fileContent) {
177
+ return fileContent.gsub(/(\.version *= *')(.*')/, "\\1" + newVersion + "'")
178
+ })
179
+ ]).process()
180
+ `git add #{specName}
181
+ git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
182
+ end
183
+
155
184
  ## --- option for setting using prebuild framework ---
156
185
  def parse_pod_dev_env(name, requirements)
157
-
158
-
159
186
  options = requirements.last
160
187
  pod_name = Specification.root_name(name)
161
188
  last_options = $processedPodsOptions[pod_name]
162
189
 
163
- if name == "YDOfflineDictQuerier"
164
- UI.puts name
165
- UI.puts requirements
166
- UI.puts "last"
167
- UI.puts last_options
168
- end
169
-
170
190
  if (last_options != nil)
171
191
  UI.message "#{name.green} use last_options: #{last_options.to_s.green}"
172
192
  if options != nil && options.is_a?(Hash)
@@ -199,22 +219,61 @@ class Podfile
199
219
  if tag == nil || tag.length == 0
200
220
  raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
201
221
  end
202
- if dev_env == 'dev'
222
+
223
+ if dev_env == 'subtree'
224
+ if !File.directory?(path)
225
+ _toplevelDir = `git rev-parse --show-toplevel`
226
+ _currentDir = `pwd`
227
+ _subtreeDir = path
228
+ if _currentDir != _toplevelDir
229
+ Dir.chdir(_toplevelDir)
230
+ _end = path
231
+ if _end[0,2] == './'
232
+ _end = _end[1, _end.length - 1]
233
+ else
234
+ _end = '/' + _end
235
+ end
236
+ _subtreeDir = './' + _currentDir[_toplevelDir.length, _currentDir.length - _toplevelDir.length] + path
237
+ end
238
+ _cmd = "git subtree add --prefix #{_subtreeDir} #{git} #{branch} --squash"
239
+ UI.puts _cmd
240
+ system(_cmd)
241
+ Dir.chdir(_currentDir)
242
+ end
243
+ options[:path] = path
244
+ if requirements.length >= 2
245
+ requirements.delete_at(0)
246
+ end
247
+ UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
248
+ elsif dev_env == 'dev'
203
249
  # 开发模式,使用path方式引用本地的submodule git库
204
250
  if !File.directory?(path)
205
251
  UI.puts "add submodule for #{pod_name.green}".yellow
206
- # TODO 这个命令要想办法展示实际报错信息
207
- `git submodule add --force -b #{branch} #{git} #{path}`
208
- if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
209
- searchAndOpenLocalExample(path)
252
+ _cmd = "git submodule add --force -b #{branch} #{git} #{path}"
253
+ UI.puts _cmd
254
+ system(_cmd)
255
+
256
+ _currentDir = Dir.pwd
257
+ Dir.chdir(path)
258
+
259
+ curGitRemoteUrl = `git remote get-url origin`.rstrip()
260
+ if curGitRemoteUrl == git
261
+ _cmd = "git reset --hard"
262
+ UI.puts _cmd
263
+ system(_cmd)
210
264
  end
265
+ Dir.chdir(_currentDir)
266
+
267
+ # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
268
+ # searchAndOpenLocalExample(path)
269
+ # end
211
270
  if !checkTagIsEqualToHead(tag, path) && !checkTagIsEqualToHead("#{tag}_beta", path)
212
271
  raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
213
272
  end
214
273
  else
215
- if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
216
- searchAndOpenLocalExample(path)
217
- end
274
+ # if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
275
+ # searchAndOpenLocalExample(path)
276
+ # end
218
277
  end
219
278
  options[:path] = path
220
279
  if requirements.length >= 2
@@ -223,25 +282,32 @@ class Podfile
223
282
  UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
224
283
  elsif dev_env == 'beta'
225
284
  # Beta模式,使用tag引用远端git库的代码
285
+ originTag = tag
226
286
  tag = "#{tag}_beta"
227
287
  if File.directory?(path)
228
288
  # 从Dev模式刚刚切换过来,需要打tag并且push
229
289
  UI.puts "release beta-version for #{pod_name.green}".yellow
230
- currentDir = Dir.pwd
290
+ _currentDir = Dir.pwd
231
291
  Dir.chdir(path)
232
- checkGitStatusAndPush(pod_name)
233
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
234
- ret = addGitTagAndPush(tag, pod_name)
235
- if ret != true
292
+ # 已经进入到podspec的文件夹中了
293
+ checkGitStatusAndPush(pod_name) # push一下
294
+ ret = checkRemoteTagExist(tag)
295
+ if ret == true
296
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
236
297
  if checkTagOrBranchIsEqalToHead(tag, "./")
237
- UI.puts "#{pod_name.green} 没做任何调整,切换回beta"
298
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag"
238
299
  else
239
300
  if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
240
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
301
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
241
302
  end
242
303
  end
304
+ else
305
+ # tag不存在,
306
+ changeVersionInCocoapods(pod_name, originTag)
307
+ checkGitStatusAndPush(pod_name) # 再push一下
308
+ addGitTagAndPush(tag, pod_name)
243
309
  end
244
- Dir.chdir(currentDir)
310
+ Dir.chdir(_currentDir)
245
311
  checkAndRemoveSubmodule(path)
246
312
  end
247
313
  options[:git] = git
@@ -254,18 +320,19 @@ class Podfile
254
320
  # Release模式,直接使用远端对应的版本
255
321
  if File.directory?(path)
256
322
  UI.puts "release release-version for #{pod_name.green}".yellow
257
- currentDir = Dir.pwd
323
+ _currentDir = Dir.pwd
258
324
  Dir.chdir(path)
259
325
  verboseParamStr = ""
260
326
  if Config.instance.verbose
261
327
  verboseParamStr = " --verbose"
262
328
  end
263
- ret = system("pod lib lint --skip-import-validation --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
329
+ ret = system("pod lib lint --skip-import-validation --fail-fast --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
264
330
  if ret != true
265
331
  raise "💔 #{pod_name.yellow} lint 失败"
266
332
  end
267
333
  checkGitStatusAndPush(pod_name)
268
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
334
+ changeVersionInCocoapods(pod_name, tag)
335
+ checkGitStatusAndPush(pod_name)
269
336
  ret = addGitTagAndPush(tag, pod_name)
270
337
  if ret == false
271
338
  if checkTagOrBranchIsEqalToHead(tag, "./")
@@ -276,7 +343,7 @@ class Podfile
276
343
  end
277
344
  ## TODO:: 发布到的目标库名称需要用变量设置
278
345
  repoAddrs = getUserRepoAddress()
279
- cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings#{getReposStrForLint()}"
346
+ cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings --use-modular-headers#{getReposStrForLint()}#{verboseParamStr}"
280
347
  UI.puts cmd.green
281
348
  ret = system(cmd)
282
349
  if ret != true
@@ -284,7 +351,7 @@ class Podfile
284
351
  end
285
352
  ## 到最后统一执行,判断如果当次release过
286
353
  `pod repo update`
287
- Dir.chdir(currentDir)
354
+ Dir.chdir(_currentDir)
288
355
  checkAndRemoveSubmodule(path)
289
356
  end
290
357
  if requirements.length < 2
@@ -294,7 +361,7 @@ class Podfile
294
361
  else
295
362
  raise "💔 :dev_env 必须要设置成 dev/beta/release之一,不接受其他值"
296
363
  end
297
- $processedPodsOptions[pod_name] = options
364
+ $processedPodsOptions[pod_name] = options.clone
298
365
  requirements.pop if options.empty?
299
366
  end
300
367
  end
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-dev-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 吴锡苗
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,6 +57,7 @@ files:
57
57
  - lib/cocoapods/dev/env.rb
58
58
  - lib/cocoapods/dev/env/version.rb
59
59
  - lib/cocoapods_plugin.rb
60
+ - lib/file_processer.rb
60
61
  homepage: https://github.com/YoudaoMobile/cocoapods-dev-env
61
62
  licenses:
62
63
  - MIT
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.0.3
83
+ rubygems_version: 3.2.5
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: a cocoapod plugin for dev in mutipods