cocoapods-dev-env 0.9.2 → 0.9.9

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: a6ef1f311749dfda8fe62e3edef726bb735d556ad02653554fd54ff66770602c
4
- data.tar.gz: 8c845b54a33e312faef38db386f712b578758f35c2bbaed17211f887243da539
3
+ metadata.gz: c819e17e2e938cabcc1855c0990b2d0eaaba2af6f53af8a16677c341bc055429
4
+ data.tar.gz: 73f66541b3cf873f2b88e99766b103dc388551ac06b315bad6862b3658f98e67
5
5
  SHA512:
6
- metadata.gz: 32462311303b31c4d70aa6642219a3c53d9178c6a9ff7804bc23e2fd029ab34b178bef0d8edb795c5686d403baf335518d10d52b1446fb7e6b783e7eed171fde
7
- data.tar.gz: d5cd32f589aa2c9f9cfb21106d71476ab39eb15ee4320f63372effd519b89382dea03b32b659ce2699ed7e85010e3b9c17e13368eeb82daca30bab1b3b68b3c4
6
+ metadata.gz: 1b3838c06c15f347f2464c6b641e6781f9c3d1166c8f32897db7c728c3595ab1736b95beb8f3624bc8174b45d9c099d53949a271d235a46f4d36035a5f00c585
7
+ data.tar.gz: 5f91efccbc4ed658d2c5383ed0555649bd42491631c26aef42b5235028ec18e2d1decbc833fb27d5bd9991a07d39b39a16f7ad2ad655627d56278e8e71044166
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.2"
4
+ VERSION = "0.9.9"
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
@@ -21,13 +23,13 @@ module Pod
21
23
  def self.keyword
22
24
  :dev_env # 'dev'/'beta'/'release'
23
25
  end
24
- puts "🎉 plugin cocoapods-dev-env loaded 🎉".green
26
+ UI.message "🎉 plugin cocoapods-dev-env loaded 🎉".green
25
27
  end
26
28
  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
@@ -121,6 +133,19 @@ class Podfile
121
133
  end
122
134
  end
123
135
 
136
+ def getReposStrForLint()
137
+ if podfile.sources.size == 0
138
+ return ""
139
+ end
140
+ str = " --sources="
141
+ podfile.sources.each do |source|
142
+ str += source
143
+ str += ","
144
+ end
145
+ UI.puts str
146
+ return str
147
+ end
148
+
124
149
  def getUserRepoAddress()
125
150
  if podfile.sources.size == 0
126
151
  raise "💔 发布release必须配置仓库的地址, e.g.: source 'https://github.com/CocoaPods/Specs.git'"
@@ -136,14 +161,28 @@ class Podfile
136
161
  index = STDIN.gets.to_i - 1
137
162
  end until (index >= 0 && index < podfile.sources.size)
138
163
  source = podfile.sources[index]
164
+ UI.puts "#{"选择了发布到: ".yellow}. #{source.green}(#{index + 1})"
139
165
  return source
140
166
  end
141
167
 
168
+ def changeVersionInCocoapods(name, newVersion)
169
+ specName = name + ".podspec"
170
+ FileProcesserManager.new(specName,
171
+ [
172
+ FileProcesser.new(-> (fileContent) {
173
+ return fileContent.gsub(/(\.version *= *')(.*')/, "\\1" + newVersion + "'")
174
+ })
175
+ ]).process()
176
+ `git add #{specName}
177
+ git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
178
+ end
179
+
142
180
  ## --- option for setting using prebuild framework ---
143
181
  def parse_pod_dev_env(name, requirements)
144
182
  options = requirements.last
145
183
  pod_name = Specification.root_name(name)
146
184
  last_options = $processedPodsOptions[pod_name]
185
+
147
186
  if (last_options != nil)
148
187
  UI.message "#{name.green} use last_options: #{last_options.to_s.green}"
149
188
  if options != nil && options.is_a?(Hash)
@@ -176,22 +215,61 @@ class Podfile
176
215
  if tag == nil || tag.length == 0
177
216
  raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
178
217
  end
179
- if dev_env == 'dev'
218
+
219
+ if dev_env == 'subtree'
220
+ if !File.directory?(path)
221
+ _toplevelDir = `git rev-parse --show-toplevel`
222
+ _currentDir = `pwd`
223
+ _subtreeDir = path
224
+ if _currentDir != _toplevelDir
225
+ Dir.chdir(_toplevelDir)
226
+ _end = path
227
+ if _end[0,2] == './'
228
+ _end = _end[1, _end.length - 1]
229
+ else
230
+ _end = '/' + _end
231
+ end
232
+ _subtreeDir = './' + _currentDir[_toplevelDir.length, _currentDir.length - _toplevelDir.length] + path
233
+ end
234
+ _cmd = "git subtree add --prefix #{_subtreeDir} #{git} #{branch} --squash"
235
+ UI.puts _cmd
236
+ system(_cmd)
237
+ Dir.chdir(_currentDir)
238
+ end
239
+ options[:path] = path
240
+ if requirements.length >= 2
241
+ requirements.delete_at(0)
242
+ end
243
+ UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
244
+ elsif dev_env == 'dev'
180
245
  # 开发模式,使用path方式引用本地的submodule git库
181
246
  if !File.directory?(path)
182
247
  UI.puts "add submodule for #{pod_name.green}".yellow
183
- # TODO 这个命令要想办法展示实际报错信息
184
- `git submodule add --force -b #{branch} #{git} #{path}`
185
- if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
186
- searchAndOpenLocalExample(path)
248
+ _cmd = "git submodule add --force -b #{branch} #{git} #{path}"
249
+ UI.puts _cmd
250
+ system(_cmd)
251
+
252
+ _currentDir = Dir.pwd
253
+ Dir.chdir(path)
254
+
255
+ curGitRemoteUrl = `git remote get-url origin`.rstrip()
256
+ if curGitRemoteUrl == git
257
+ _cmd = "git reset --hard"
258
+ UI.puts _cmd
259
+ system(_cmd)
187
260
  end
261
+ Dir.chdir(_currentDir)
262
+
263
+ # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
264
+ # searchAndOpenLocalExample(path)
265
+ # end
188
266
  if !checkTagIsEqualToHead(tag, path) && !checkTagIsEqualToHead("#{tag}_beta", path)
189
267
  raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
190
268
  end
191
269
  else
192
- if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
193
- searchAndOpenLocalExample(path)
194
- end
270
+ # if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
271
+ # searchAndOpenLocalExample(path)
272
+ # end
195
273
  end
196
274
  options[:path] = path
197
275
  if requirements.length >= 2
@@ -200,25 +278,32 @@ class Podfile
200
278
  UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
201
279
  elsif dev_env == 'beta'
202
280
  # Beta模式,使用tag引用远端git库的代码
281
+ originTag = tag
203
282
  tag = "#{tag}_beta"
204
283
  if File.directory?(path)
205
284
  # 从Dev模式刚刚切换过来,需要打tag并且push
206
285
  UI.puts "release beta-version for #{pod_name.green}".yellow
207
- currentDir = Dir.pwd
286
+ _currentDir = Dir.pwd
208
287
  Dir.chdir(path)
209
- checkGitStatusAndPush(pod_name)
210
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
211
- ret = addGitTagAndPush(tag, pod_name)
212
- if ret != true
288
+ # 已经进入到podspec的文件夹中了
289
+ checkGitStatusAndPush(pod_name) # push一下
290
+ ret = checkRemoteTagExist(tag)
291
+ if ret == true
292
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
213
293
  if checkTagOrBranchIsEqalToHead(tag, "./")
214
- UI.puts "#{pod_name.green} 没做任何调整,切换回beta"
294
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag"
215
295
  else
216
296
  if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
217
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
297
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
218
298
  end
219
299
  end
300
+ else
301
+ # tag不存在,
302
+ changeVersionInCocoapods(pod_name, originTag)
303
+ checkGitStatusAndPush(pod_name) # 再push一下
304
+ addGitTagAndPush(tag, pod_name)
220
305
  end
221
- Dir.chdir(currentDir)
306
+ Dir.chdir(_currentDir)
222
307
  checkAndRemoveSubmodule(path)
223
308
  end
224
309
  options[:git] = git
@@ -231,14 +316,19 @@ class Podfile
231
316
  # Release模式,直接使用远端对应的版本
232
317
  if File.directory?(path)
233
318
  UI.puts "release release-version for #{pod_name.green}".yellow
234
- currentDir = Dir.pwd
319
+ _currentDir = Dir.pwd
235
320
  Dir.chdir(path)
236
- ret = system("pod lib lint --allow-warnings")
321
+ verboseParamStr = ""
322
+ if Config.instance.verbose
323
+ verboseParamStr = " --verbose"
324
+ end
325
+ ret = system("pod lib lint --skip-import-validation --fail-fast --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
237
326
  if ret != true
238
327
  raise "💔 #{pod_name.yellow} lint 失败"
239
328
  end
240
329
  checkGitStatusAndPush(pod_name)
241
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
330
+ changeVersionInCocoapods(pod_name, originTag)
331
+ checkGitStatusAndPush(pod_name)
242
332
  ret = addGitTagAndPush(tag, pod_name)
243
333
  if ret == false
244
334
  if checkTagOrBranchIsEqalToHead(tag, "./")
@@ -249,14 +339,15 @@ class Podfile
249
339
  end
250
340
  ## TODO:: 发布到的目标库名称需要用变量设置
251
341
  repoAddrs = getUserRepoAddress()
252
- cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --allow-warnings"
342
+ cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings#{getReposStrForLint()}"
343
+ UI.puts cmd.green
253
344
  ret = system(cmd)
254
345
  if ret != true
255
346
  raise "💔 #{pod_name.yellow} 发布失败"
256
347
  end
257
348
  ## 到最后统一执行,判断如果当次release过
258
349
  `pod repo update`
259
- Dir.chdir(currentDir)
350
+ Dir.chdir(_currentDir)
260
351
  checkAndRemoveSubmodule(path)
261
352
  end
262
353
  if requirements.length < 2
@@ -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.2
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - 吴锡苗
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-22 00:00:00.000000000 Z
11
+ date: 2021-01-08 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