cocoapods-dev-env 0.9.5 → 0.9.8

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: eba297c1e0a9132aa37caa6a96fd5d3c0c7f358ea37c7770c09d72060e21bee4
4
+ data.tar.gz: 914c791d30f0445ae40acefddcfb128128bb154ed59f7c9f2a805a149d3282eb
5
5
  SHA512:
6
- metadata.gz: 2a711c3ca0d7bc6beee77bae2b6b2255b43f642de3aebe33a4c8f4c253f28c33c2c240e751e81f87603111b389fd93cb83218d551963a35e8931da97e4bbdf60
7
- data.tar.gz: c98b59b570d976f4486c3e0bb5e53562cffbdacab07a10cf6de123415babbd71d1c35fce79ffe4285fedcedfbf5704d4ca914da904d63d57d8b4bf20441a69d1
6
+ metadata.gz: ede85195fecf0b9996882ef34cd42eb23bf32df0e439e89dc57b119bc32c5135ecde8ec04d457907e820777239c01c01147d63569481e56a53f8bef5f0cd82e9
7
+ data.tar.gz: ee4b507a7a4d52cd0821217a8fad64147b694dc25701896aa6d5f96db68c63d151d51dc5d55b7060d71634ea4b24df797a43ff364827fde600ea7a4797178d8d
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`
@@ -1,7 +1,7 @@
1
1
  module Cocoapods
2
2
  module Dev
3
3
  module Env
4
- VERSION = "0.9.5"
4
+ VERSION = "0.9.8"
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
@@ -156,10 +164,20 @@ class Podfile
156
164
  return source
157
165
  end
158
166
 
167
+ def changeVersionInCocoapods(name, newVersion)
168
+ specName = name + ".podspec"
169
+ FileProcesserManager.new(specName,
170
+ [
171
+ FileProcesser.new(-> (fileContent) {
172
+ return fileContent.gsub(/(\.version *= *')(.*')/, "\\1" + newVersion + "'")
173
+ })
174
+ ]).process()
175
+ `git add #{specName}
176
+ git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
177
+ end
178
+
159
179
  ## --- option for setting using prebuild framework ---
160
180
  def parse_pod_dev_env(name, requirements)
161
-
162
-
163
181
  options = requirements.last
164
182
  pod_name = Specification.root_name(name)
165
183
  last_options = $processedPodsOptions[pod_name]
@@ -198,6 +216,25 @@ class Podfile
198
216
  end
199
217
 
200
218
  if dev_env == 'subtree'
219
+ if !File.directory?(path)
220
+ _toplevelDir = `git rev-parse --show-toplevel`
221
+ _currentDir = `pwd`
222
+ _subtreeDir = path
223
+ if _currentDir != _toplevelDir
224
+ Dir.chdir(_toplevelDir)
225
+ _end = path
226
+ if _end[0,2] == './'
227
+ _end = _end[1, _end.length - 1]
228
+ else
229
+ _end = '/' + _end
230
+ end
231
+ _subtreeDir = './' + _currentDir[_toplevelDir.length, _currentDir.length - _toplevelDir.length] + path
232
+ end
233
+ _cmd = "git subtree add --prefix #{_subtreeDir} #{git} #{branch} --squash"
234
+ UI.puts _cmd
235
+ system(_cmd)
236
+ Dir.chdir(_currentDir)
237
+ end
201
238
  options[:path] = path
202
239
  if requirements.length >= 2
203
240
  requirements.delete_at(0)
@@ -207,8 +244,21 @@ class Podfile
207
244
  # 开发模式,使用path方式引用本地的submodule git库
208
245
  if !File.directory?(path)
209
246
  UI.puts "add submodule for #{pod_name.green}".yellow
210
- # TODO 这个命令要想办法展示实际报错信息
211
- `git submodule add --force -b #{branch} #{git} #{path}`
247
+ _cmd = "git submodule add --force -b #{branch} #{git} #{path}"
248
+ UI.puts _cmd
249
+ system(_cmd)
250
+
251
+ _currentDir = Dir.pwd
252
+ Dir.chdir(path)
253
+
254
+ curGitRemoteUrl = `git remote get-url origin`.rstrip()
255
+ if curGitRemoteUrl == git
256
+ _cmd = "git reset --hard"
257
+ UI.puts _cmd
258
+ system(_cmd)
259
+ end
260
+ Dir.chdir(_currentDir)
261
+
212
262
  # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
213
263
  # searchAndOpenLocalExample(path)
214
264
  # end
@@ -227,25 +277,32 @@ class Podfile
227
277
  UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
228
278
  elsif dev_env == 'beta'
229
279
  # Beta模式,使用tag引用远端git库的代码
280
+ originTag = tag
230
281
  tag = "#{tag}_beta"
231
282
  if File.directory?(path)
232
283
  # 从Dev模式刚刚切换过来,需要打tag并且push
233
284
  UI.puts "release beta-version for #{pod_name.green}".yellow
234
- currentDir = Dir.pwd
285
+ _currentDir = Dir.pwd
235
286
  Dir.chdir(path)
236
- checkGitStatusAndPush(pod_name)
237
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
238
- ret = addGitTagAndPush(tag, pod_name)
239
- if ret != true
287
+ # 已经进入到podspec的文件夹中了
288
+ checkGitStatusAndPush(pod_name) # push一下
289
+ ret = checkRemoteTagExist(tag)
290
+ if ret == true
291
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
240
292
  if checkTagOrBranchIsEqalToHead(tag, "./")
241
- UI.puts "#{pod_name.green} 没做任何调整,切换回beta"
293
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag"
242
294
  else
243
295
  if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
244
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
296
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
245
297
  end
246
298
  end
299
+ else
300
+ # tag不存在,
301
+ changeVersionInCocoapods(pod_name, originTag)
302
+ checkGitStatusAndPush(pod_name) # 再push一下
303
+ addGitTagAndPush(tag, pod_name)
247
304
  end
248
- Dir.chdir(currentDir)
305
+ Dir.chdir(_currentDir)
249
306
  checkAndRemoveSubmodule(path)
250
307
  end
251
308
  options[:git] = git
@@ -258,7 +315,7 @@ class Podfile
258
315
  # Release模式,直接使用远端对应的版本
259
316
  if File.directory?(path)
260
317
  UI.puts "release release-version for #{pod_name.green}".yellow
261
- currentDir = Dir.pwd
318
+ _currentDir = Dir.pwd
262
319
  Dir.chdir(path)
263
320
  verboseParamStr = ""
264
321
  if Config.instance.verbose
@@ -288,7 +345,7 @@ class Podfile
288
345
  end
289
346
  ## 到最后统一执行,判断如果当次release过
290
347
  `pod repo update`
291
- Dir.chdir(currentDir)
348
+ Dir.chdir(_currentDir)
292
349
  checkAndRemoveSubmodule(path)
293
350
  end
294
351
  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.5
4
+ version: 0.9.8
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: 2020-09-16 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