cocoapods-dev-env 0.9.1 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ca8013b453d1e257cce0f668f9d55b690728054807b87d80307d234e33bb651
4
- data.tar.gz: 24604dcbcdef57ce2cf10a2a0e376e417e3eb3336664a8dbb086d299ba7822d8
3
+ metadata.gz: eba297c1e0a9132aa37caa6a96fd5d3c0c7f358ea37c7770c09d72060e21bee4
4
+ data.tar.gz: 914c791d30f0445ae40acefddcfb128128bb154ed59f7c9f2a805a149d3282eb
5
5
  SHA512:
6
- metadata.gz: 650079c36c495a2a9384972b92a40ffc770031c4158914e54e1e7e69c45e2937b88a3080d5dbb7eaa13b9aaed248aea545cd6383acaef36613f82d684d3ea1d9
7
- data.tar.gz: 7f30ffe0691428cc7b50ebbfb86c6b3d3d77ede2b6edd657fc3fb7d44b002cfff1735f65c095c3a518a2288760a85c515138a9a8e08d7ebed440740430e2749d
6
+ metadata.gz: ede85195fecf0b9996882ef34cd42eb23bf32df0e439e89dc57b119bc32c5135ecde8ec04d457907e820777239c01c01147d63569481e56a53f8bef5f0cd82e9
7
+ data.tar.gz: ee4b507a7a4d52cd0821217a8fad64147b694dc25701896aa6d5f96db68c63d151d51dc5d55b7060d71634ea4b24df797a43ff364827fde600ea7a4797178d8d
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.1"
4
+ VERSION = "0.9.8"
5
5
  end
6
6
  end
7
7
  end
@@ -1,10 +1,13 @@
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
4
6
  # forbidden submodule not cloned
5
- `
6
- git submodule update --init --recursive
7
- `
7
+ # 会引起submodule HEAD回滚,不靠谱,先注释掉
8
+ # `
9
+ # git submodule update --init --recursive
10
+ # `
8
11
  end
9
12
 
10
13
  Pod::HooksManager.register('cocoapods-dev-env', :post_install) do |installer|
@@ -20,13 +23,26 @@ module Pod
20
23
  def self.keyword
21
24
  :dev_env # 'dev'/'beta'/'release'
22
25
  end
23
- puts "🎉 plugin cocoapods-dev-env loaded 🎉".green
26
+ UI.message "🎉 plugin cocoapods-dev-env loaded 🎉".green
24
27
  end
25
28
  class Podfile
26
29
  class TargetDefinition
27
30
 
31
+ def searchAndOpenLocalExample(path)
32
+ _currentDir = Dir.pwd
33
+ Dir.chdir(path)
34
+ Dir.chdir("Example")
35
+ `pod install`
36
+ projPaths = Dir::glob("*.xcworkspace")
37
+ if projPaths.count > 0
38
+ `open -a Terminal ./`
39
+ `open #{projPaths[0]}`
40
+ end
41
+ Dir.chdir(_currentDir)
42
+ end
43
+
28
44
  def checkAndRemoveSubmodule(path)
29
- currentDir = Dir.pwd
45
+ _currentDir = Dir.pwd
30
46
  Dir.chdir(path)
31
47
  output = `git status -s`
32
48
  puts output
@@ -38,7 +54,7 @@ class Podfile
38
54
  else
39
55
  raise "submodule #{path} 移除失败,有未提交的修改"
40
56
  end
41
- Dir.chdir(currentDir)
57
+ Dir.chdir(_currentDir)
42
58
  `
43
59
  git submodule deinit #{path}
44
60
  rm -rf #{path}
@@ -47,10 +63,10 @@ class Podfile
47
63
  end
48
64
 
49
65
  def checkTagIsEqualToHead(tag, path)
50
- currentDir = Dir.pwd
66
+ _currentDir = Dir.pwd
51
67
  Dir.chdir(path)
52
68
  result = `git describe --abbrev=4 HEAD`
53
- Dir.chdir(currentDir)
69
+ Dir.chdir(_currentDir)
54
70
  if result.include?(tag)
55
71
  return true
56
72
  else
@@ -60,12 +76,12 @@ class Podfile
60
76
 
61
77
  # 这个函数有问题有时候拿不到相同的commit id
62
78
  def checkTagOrBranchIsEqalToHead(branchOrTag, path)
63
- currentDir = Dir.pwd
79
+ _currentDir = Dir.pwd
64
80
  Dir.chdir(path)
65
81
  headCommitID = `git rev-parse HEAD`
66
82
  tagCommitID = `git rev-parse #{branchOrTag}`
67
83
  UI.puts "#{`pwd`} headCommitID:#{headCommitID} \n #{branchOrTag}ComitID:#{tagCommitID}"
68
- Dir.chdir(currentDir)
84
+ Dir.chdir(_currentDir)
69
85
  return (headCommitID.length > 0 && headCommitID == tagCommitID)
70
86
  end
71
87
 
@@ -85,6 +101,12 @@ class Podfile
85
101
  end
86
102
  end
87
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
+
88
110
  def addGitTagAndPush(tag, pod_name)
89
111
  ret = system("git tag #{tag}")
90
112
  if ret == true
@@ -97,8 +119,12 @@ class Podfile
97
119
  end
98
120
 
99
121
  def inputNeedJumpForReson(str)
100
- puts str
101
- puts '是(Y), 否(N)'
122
+ if ARGV.include? '--silent'
123
+ return false
124
+ end
125
+
126
+ puts str.green
127
+ puts '是(Y), 任意其他输入或直接回车跳过'.green
102
128
  input = STDIN.gets
103
129
  if input[0,1] == "Y"
104
130
  return true
@@ -107,6 +133,19 @@ class Podfile
107
133
  end
108
134
  end
109
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
+
110
149
  def getUserRepoAddress()
111
150
  if podfile.sources.size == 0
112
151
  raise "💔 发布release必须配置仓库的地址, e.g.: source 'https://github.com/CocoaPods/Specs.git'"
@@ -125,11 +164,24 @@ class Podfile
125
164
  return source
126
165
  end
127
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
+
128
179
  ## --- option for setting using prebuild framework ---
129
180
  def parse_pod_dev_env(name, requirements)
130
181
  options = requirements.last
131
182
  pod_name = Specification.root_name(name)
132
183
  last_options = $processedPodsOptions[pod_name]
184
+
133
185
  if (last_options != nil)
134
186
  UI.message "#{name.green} use last_options: #{last_options.to_s.green}"
135
187
  if options != nil && options.is_a?(Hash)
@@ -162,43 +214,95 @@ class Podfile
162
214
  if tag == nil || tag.length == 0
163
215
  raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
164
216
  end
165
- if dev_env == 'dev'
217
+
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
238
+ options[:path] = path
239
+ if requirements.length >= 2
240
+ requirements.delete_at(0)
241
+ end
242
+ UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
243
+ elsif dev_env == 'dev'
166
244
  # 开发模式,使用path方式引用本地的submodule git库
167
245
  if !File.directory?(path)
168
246
  UI.puts "add submodule for #{pod_name.green}".yellow
169
- # TODO 这个命令要想办法展示实际报错信息
170
- `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)
171
261
 
262
+ # if inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
263
+ # searchAndOpenLocalExample(path)
264
+ # end
172
265
  if !checkTagIsEqualToHead(tag, path) && !checkTagIsEqualToHead("#{tag}_beta", path)
173
266
  raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
174
267
  end
268
+ else
269
+ # if inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
270
+ # searchAndOpenLocalExample(path)
271
+ # end
175
272
  end
176
273
  options[:path] = path
177
274
  if requirements.length >= 2
178
275
  requirements.delete_at(0)
179
276
  end
180
- UI.message "enabled #{"dev".green}-mode for #{pod_name.green}"
277
+ UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
181
278
  elsif dev_env == 'beta'
182
279
  # Beta模式,使用tag引用远端git库的代码
280
+ originTag = tag
183
281
  tag = "#{tag}_beta"
184
282
  if File.directory?(path)
185
283
  # 从Dev模式刚刚切换过来,需要打tag并且push
186
284
  UI.puts "release beta-version for #{pod_name.green}".yellow
187
- currentDir = Dir.pwd
285
+ _currentDir = Dir.pwd
188
286
  Dir.chdir(path)
189
- checkGitStatusAndPush(pod_name)
190
- ## TODO:: 检查tag版本号与podspec里的版本号是否一致
191
- ret = addGitTagAndPush(tag, pod_name)
192
- if ret != true
287
+ # 已经进入到podspec的文件夹中了
288
+ checkGitStatusAndPush(pod_name) # push一下
289
+ ret = checkRemoteTagExist(tag)
290
+ if ret == true
291
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
193
292
  if checkTagOrBranchIsEqalToHead(tag, "./")
194
- UI.puts "#{pod_name.green} 没做任何调整,切换回beta"
293
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag"
195
294
  else
196
295
  if !inputNeedJumpForReson("是否跳过beta发布并删除本地submodule(直接引用远端库)")
197
- raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
296
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
198
297
  end
199
298
  end
299
+ else
300
+ # tag不存在,
301
+ changeVersionInCocoapods(pod_name, originTag)
302
+ checkGitStatusAndPush(pod_name) # 再push一下
303
+ addGitTagAndPush(tag, pod_name)
200
304
  end
201
- Dir.chdir(currentDir)
305
+ Dir.chdir(_currentDir)
202
306
  checkAndRemoveSubmodule(path)
203
307
  end
204
308
  options[:git] = git
@@ -211,9 +315,13 @@ class Podfile
211
315
  # Release模式,直接使用远端对应的版本
212
316
  if File.directory?(path)
213
317
  UI.puts "release release-version for #{pod_name.green}".yellow
214
- currentDir = Dir.pwd
318
+ _currentDir = Dir.pwd
215
319
  Dir.chdir(path)
216
- ret = system("pod lib lint --allow-warnings")
320
+ verboseParamStr = ""
321
+ if Config.instance.verbose
322
+ verboseParamStr = " --verbose"
323
+ end
324
+ ret = system("pod lib lint --skip-import-validation --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
217
325
  if ret != true
218
326
  raise "💔 #{pod_name.yellow} lint 失败"
219
327
  end
@@ -229,14 +337,15 @@ class Podfile
229
337
  end
230
338
  ## TODO:: 发布到的目标库名称需要用变量设置
231
339
  repoAddrs = getUserRepoAddress()
232
- cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --allow-warnings"
340
+ cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings#{getReposStrForLint()}"
341
+ UI.puts cmd.green
233
342
  ret = system(cmd)
234
343
  if ret != true
235
344
  raise "💔 #{pod_name.yellow} 发布失败"
236
345
  end
237
346
  ## 到最后统一执行,判断如果当次release过
238
347
  `pod repo update`
239
- Dir.chdir(currentDir)
348
+ Dir.chdir(_currentDir)
240
349
  checkAndRemoveSubmodule(path)
241
350
  end
242
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.1
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: 2019-11-11 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
@@ -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.6
83
+ rubygems_version: 3.0.3
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: a cocoapod plugin for dev in mutipods