cocoapods-bb-PodAssistant 0.1.7 → 0.1.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: 7a9981c561f8eb760349f20d77d0afd544602a810472cb9f8ecd02d6e2779664
4
- data.tar.gz: da2528d18dfe9a93eafd8c18de120ba5212663c845bce0473f3c5fbbb056a8ba
3
+ metadata.gz: 95c6d433814654744108bb1b8d1051ac00b37dff52e8d0c73fbb03bbb7d67d52
4
+ data.tar.gz: d804e3f603a8ed9e8612fb4edf6c5ed19ae543d2328dfaf92bf335664f0da421
5
5
  SHA512:
6
- metadata.gz: 8adc406969d02c2cb60393ff1afbba8a3e909acee63b85643183e72e58e3f087b156022037059a90a2ebe348c1ec832720ff7d5b66a637c42cc64ab0ff9925e8
7
- data.tar.gz: a02261b3e1006d4d8164646843bc02414442ede74086dc763b66a41fe560610730797fc167f1662e4229f96d84cb867ab664c6f209fe5160108b06b63d56eea8
6
+ metadata.gz: 75858bf2163338409042d5e4be54e38d6c08a8ea93df77341870af4a0425bd1dc9a1b8a905376775b958318b554b537d4a0b9ad0f822f92d67ed53b82d0ccf04
7
+ data.tar.gz: 8216d2c5d5df66e7ff8526ae9394ba0a11c1391ac3f6c835e997458417aacab84d3372b346f9caaa565f087679448d094719c5b80ad48c29aeb04de1ed4691d6
@@ -1,5 +1,4 @@
1
1
  require 'cocoapods-bb-PodAssistant/config/source_manager'
2
- require 'cocoapods-bb-PodAssistant/helpers/stable_env_helper'
3
2
 
4
3
  module Pod
5
4
  class Command
@@ -18,17 +17,11 @@ module Pod
18
17
 
19
18
  def run
20
19
  # verify_podfile_exists!
21
- env = BB::StableEnv.new()
22
- if env.verify_stable_env_exists == true
23
- env.system_clone_stable_git # 自动拉取远端git仓库数据
24
- source_manager = BB::SourceManager.new()
25
- puts "[PodAssistant] 开始配置生成当前项目yml文件".yellow
26
- # 生成本地yml配置
27
- source_manager.generate_localStable
28
- puts "[PodAssistant] `pod stable init` complete!".green
29
- else
30
- puts "[PodAssistant] ❌工程没有配置stable环境".red
31
- end
20
+ source_manager = BB::SourceManager.new()
21
+ puts "[PodAssistant] 开始配置生成当前项目yml文件".yellow
22
+ # 生成本地yml配置
23
+ source_manager.generate_localStable
24
+ puts "[PodAssistant] `pod stable init` complete!".green
32
25
  end
33
26
 
34
27
  end
@@ -7,10 +7,6 @@ module Pod
7
7
  class Command
8
8
  class Stable < Command
9
9
  class Sync < Stable
10
- require 'fileutils'
11
- require 'cocoapods/executable.rb'
12
- extend Executable
13
- executable :git
14
10
 
15
11
  self.summary = '[同步远端yml配置] sync a Stable yml config file'
16
12
 
@@ -26,31 +22,10 @@ module Pod
26
22
  puts "开始合并远端stable yml数据".yellow
27
23
  # 数据合并
28
24
  source_manager = BB::SourceManager.new()
29
- fetch_stale_git
30
25
  source_manager.merge_stable_data
31
26
  puts "[PodAssistant] `pod stable sync` complete! Please execute the [pod install/ pod update] command".green
32
27
  end
33
28
 
34
- # 拉取stable仓库代码 ruby脚本内部调用
35
- def clone_stable_git
36
- cache = BB::Cache.new()
37
- cachePath = cache.cachePath
38
- configGitPath(cachePath)
39
- unless Dir.exist?(File.join(cachePath))
40
- clonePath = File.dirname(cachePath)
41
- FileUtils.mkdir_p clonePath
42
- git_clone(@stable_source,clonePath)
43
- end
44
- end
45
-
46
- def fetch_stale_git
47
- clone_stable_git
48
- # git操作
49
- git_reset
50
- git_fetch
51
- git_checkout_and_pull(@stable_source, @stable_branch, @stable_tag)
52
- end
53
-
54
29
  end
55
30
  end
56
31
  end
@@ -21,26 +21,37 @@ module Pod
21
21
 
22
22
  def self.options
23
23
  [
24
- # ['--business-spec=specName', '业务线公共stable spec名称'],
24
+ ['--sync', '立即同步远端yml配置,更新组件信息'],
25
25
  ].concat(super)
26
26
  end
27
27
 
28
28
  def initialize(argv)
29
29
  @pods = argv.arguments!
30
+ @sync = argv.flag?('sync')
30
31
  super
31
-
32
32
  end
33
33
 
34
34
  def run
35
35
  puts "[PodAssistant] 开始执行 $ pod stable update".yellow
36
+ # system "git checkout Podfile.lock"
37
+ source_manager = BB::SourceManager.new()
36
38
  # verify_podfile_exists! # 系统提供api验证podfile是否ok
39
+ if @sync
40
+ puts "[PodAssistant] 需要同步组件信息#{@pods}".green
41
+ source_manager.merge_stable_data(@pods)
42
+ end
43
+ podStartTime = Time.new
37
44
  if @pods.any?
38
45
  pods_str = @pods.join(" ")
39
46
  system "pod update #{pods_str}"
40
47
  else
41
48
  system "pod update"
42
49
  end
43
- source_manager = BB::SourceManager.new()
50
+ podEndTime = Time.new
51
+ # 获取时间差
52
+ time = podEndTime - podStartTime
53
+ puts "[PodAssistant] pod update操作总耗时【#{time.to_s.send(:red)}秒】start:#{podStartTime} end:#{podEndTime}".green
54
+
44
55
  source_manager.update_local_stable_from_podmodules(@pods)
45
56
  puts "[PodAssistant] `pod stable update` complete!".green
46
57
  end
@@ -1,4 +1,5 @@
1
1
  require 'cocoapods-bb-PodAssistant/config/stable_source'
2
+ require 'cocoapods-bb-PodAssistant/helpers/pod_utils'
2
3
 
3
4
  module BB
4
5
  class Cache
@@ -7,10 +8,15 @@ module BB
7
8
  stable_source = StableSource.stable_default_source
8
9
  end
9
10
  @stable_source = stable_source
11
+ @bundleId = BB::PodUtils.getProjectBundleIdentifier
12
+ if @bundleId.nil?
13
+ @bundleId = 'stable'
14
+ end
10
15
  end
11
16
 
12
17
  def cachePath()
13
- File.join(File.expand_path('~/.cache'), 'cocoapods-bb-PodAssistant','stable',@stable_source.split('/').last.chomp('.git').to_s)
18
+ # 缓存路径采用bundle包名区分,解决多产品同时打包问题
19
+ File.join(File.expand_path('~/.cache'), 'cocoapods-bb-PodAssistant',@bundleId,@stable_source.split('/').last.chomp('.git').to_s)
14
20
  end
15
21
  end
16
22
  end
@@ -9,6 +9,7 @@ module BB
9
9
  class SourceManager
10
10
  def initialize()
11
11
  env = BB::StableEnv.new()
12
+ # puts "SourceManager env:#{env}".red
12
13
  @businessSpecName = env.business_stable
13
14
  @stableMgr = BB::StableManager.new()
14
15
  end
@@ -93,10 +94,10 @@ module BB
93
94
  localSpec.writeData(local_stable_yaml, stable_lock)
94
95
  end
95
96
 
96
- # 合并stable数据
97
- def merge_stable_data()
97
+ # 合并stable数据,参数,支持传入更新某几个数据
98
+ def merge_stable_data(update_pods=[])
98
99
  #4、show origin_stable_lock diff with local_stable_lock
99
- new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas)
100
+ new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas, update_pods)
100
101
 
101
102
  #5、rewirte local_stable_lock with origin_stable_lock
102
103
  update_localstable_datas(new_stable_spec)
@@ -122,8 +123,8 @@ module BB
122
123
  return result
123
124
  end
124
125
 
125
- # compare specs 参数1:本地,参数2:远端
126
- def compare_specs(local_specs, common_specs)
126
+ # compare specs 参数1:本地,参数2:远端,参数3:指定更新pod库
127
+ def compare_specs(local_specs, common_specs, update_pods=[])
127
128
  added_projects = []
128
129
  updated_projects = []
129
130
  rollbacked_projects = []
@@ -146,15 +147,15 @@ module BB
146
147
  elsif local_version != version
147
148
  # puts "merge name:#{name} local_version:#{local_version} route_version:#{version}".red
148
149
  # 版本不一致
149
- if (version.is_a? String) && (local_version.is_a? String)
150
- end
151
- if versionGreat(version, local_version)
152
- updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})"
153
- else
154
- rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})"
155
- end
156
150
  podCoreName = subspec_podname(name)
157
- need_update_pod_lists[podCoreName] = version
151
+ if (update_pods.length == 0) || (update_pods.include?(podCoreName))
152
+ if versionGreat(version, local_version)
153
+ updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})"
154
+ else
155
+ rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})"
156
+ end
157
+ need_update_pod_lists[podCoreName] = version
158
+ end
158
159
  end
159
160
  end
160
161
  # 解决subspec组件同步更新版本信息
@@ -175,16 +176,20 @@ module BB
175
176
  end
176
177
  local_exist_ver = new_specs[name]
177
178
  if local_exist_ver.nil?
178
- new_specs[name] = version
179
- added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
179
+ if (update_pods.length == 0) || (update_pods.include?(name))
180
+ new_specs[name] = version
181
+ added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
182
+ end
180
183
  end
181
184
  if array.is_a?(Array)
182
185
  array.each do |name|
183
186
  name = name.to_s
184
187
  local_exist_ver = new_specs[name]
185
188
  if local_exist_ver.nil?
186
- new_specs[name] = version
187
- added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
189
+ if (update_pods.length == 0) || (update_pods.include?(name))
190
+ new_specs[name] = version
191
+ added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
192
+ end
188
193
  end
189
194
  end
190
195
  end
@@ -192,7 +197,6 @@ module BB
192
197
  # step.3 匹配组件移除
193
198
  removedata.each do |name|
194
199
  name = name.to_s
195
- # local_exist_ver = new_specs[name]
196
200
  version = listdata[name]
197
201
  if version
198
202
  deleted_projects << "【#{name}】 (#{"delete".send(:red)}) <- (#{version})"
@@ -244,6 +248,8 @@ module BB
244
248
  lockfile = podfile_lock
245
249
  local_specs = {}
246
250
  dependencies = lockfile.dependencies
251
+ pod_names = lockfile.pod_names
252
+ # dependencies依赖数据
247
253
  dependencies.each do | dependency |
248
254
  pod_name = dependency.name
249
255
  if has_include_subspec(pod_name)
@@ -251,6 +257,7 @@ module BB
251
257
  else
252
258
  podCoreName = pod_name
253
259
  end
260
+ # puts "podCoreName:#{podCoreName} pod_name:#{pod_name}".red
254
261
  if dependency.external_source.is_a? Hash
255
262
  # 指向分支
256
263
  external_source = dependency.external_source
@@ -273,6 +280,25 @@ module BB
273
280
  end
274
281
  end
275
282
  end
283
+ # 被依赖数据
284
+ pod_names.each do | pod_name |
285
+ if has_include_subspec(pod_name)
286
+ podCoreName = subspec_podname(pod_name)
287
+ else
288
+ podCoreName = pod_name
289
+ end
290
+ pod = local_specs[podCoreName]
291
+ # puts "podCoreName:#{podCoreName} pod:#{pod}".green
292
+ if pod.nil?
293
+ # 指向标签版本
294
+ version = lockfile.version(pod_name).to_s
295
+ if !version.empty? && !local_specs.has_key?(podCoreName)
296
+ local_specs[podCoreName] = version
297
+ # puts "[标签] #{podCoreName} => (#{version})".yellow
298
+ end
299
+ end
300
+ end
301
+
276
302
  # Pod::UI.puts "yml配置数据:#{local_specs}"
277
303
  if local_specs.length > 0
278
304
  update_localstable_datas(local_specs)
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBbPodassistant
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -158,6 +158,10 @@ module BB
158
158
  need_update_pod_data={}
159
159
  stable_hash = local_stable_data
160
160
  podfile_hash.each do |podName,podfile_pod|
161
+ if podfile_pod.count == 0
162
+ puts "❌ podfile组件配置异常,请确认:method => REMOTE_VERSION是否配置\n组件信息如下:\n#{podName} => #{podfile_pod}".red
163
+ exit
164
+ end
161
165
  podCoreName = @source_manager.subspec_podname(podName)
162
166
  if (podName == podCoreName) || @source_manager.has_pod_subspec(podName, podCoreName)
163
167
  pod = stable_hash[podCoreName]
@@ -165,7 +169,8 @@ module BB
165
169
  need_update_pod_data[podName] = podfile_pod
166
170
  else
167
171
  # if podCoreName == 'BBGameModule'
168
- # puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod})".green
172
+ # succ = (pod == podfile_pod) ? true : false
173
+ # puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod}) succ:#{succ}".green
169
174
  # end
170
175
  if pod == podfile_pod
171
176
  if podName != podCoreName
@@ -7,6 +7,11 @@ module BB
7
7
  configGitPath(@cache.cachePath)
8
8
  # 自动加载stable环境
9
9
  loadStaleEnv
10
+ if verify_stable_env_exists == false
11
+ puts "[PodAssistant] ❌工程没有配置stable环境".red
12
+ else
13
+ fetch_stale_git # 自动拉取远端git仓库数据
14
+ end
10
15
  end
11
16
 
12
17
  # stable 环境,执行pod stable
@@ -36,15 +41,31 @@ module BB
36
41
  def system_clone_stable_git
37
42
  cachePath = @cache.cachePath
38
43
  puts "hook [pod install/update] fetch stable git=>#{cachePath}"
39
- if Dir.exist?(File.join(cachePath))
40
- # `cd #{cachePath}; git switch main; git pull --all`
41
- system "cd #{cachePath}; git switch main; git pull --all"
42
- else
44
+ if !Dir.exist?(File.join(cachePath))
43
45
  clonePath = File.dirname(cachePath)
44
46
  FileUtils.mkdir_p clonePath
45
- # `git clone #{@stable_source} #{cachePath}`
46
47
  system "git clone #{@stable_source} #{cachePath}"
47
48
  end
49
+ if verify_branch_exists
50
+ if stable_tag || stable_branch
51
+ if stable_branch
52
+ system "cd #{cachePath}; git checkout #{stable_branch}; git reset --hard origin/#{stable_branch}"
53
+ end
54
+ if stable_tag
55
+ system "cd #{cachePath}; git checkout #{stable_tag};"
56
+ end
57
+ else
58
+ result =`git symbolic-ref refs/remotes/origin/HEAD`
59
+ protechBranch = result.split("/").last.strip || default_branch
60
+ system "cd #{cachePath}; git checkout #{protechBranch}; git reset --hard origin/#{protechBranch}"
61
+ end
62
+ else
63
+ puts "❌ stable配置无效分支信息source:#{@stable_source} branch:#{stable_branch}".red
64
+ exit
65
+ end
66
+ end
67
+ def fetch_stale_git
68
+ system_clone_stable_git
48
69
  end
49
70
 
50
71
  # ========podfile 约定函数规则,切勿修改
@@ -56,13 +77,19 @@ module BB
56
77
  end
57
78
  @stable_tag = options[:tag] if options.has_key?(:tag)
58
79
  @stable_branch = options[:branch] if options.has_key?(:branch)
59
- puts "###stable env => [stable公共源]:#{source} [业务线源名称]:#{@businessSpec} branch:#{@stable_branch} tag:#{@stable_tag}".yellow
80
+ puts "###stable env => [stable公共源]:#{source} [业务线源名称]:#{@businessSpec} branch:#{@stable_branch} tag:#{@stable_tag}".green
60
81
  end
61
82
 
62
83
  def stable_source
63
84
  return @stable_source
64
85
  end
86
+ def default_branch
87
+ return "main"
88
+ end
65
89
  def stable_branch
90
+ if @stable_branch.nil?
91
+ return default_branch
92
+ end
66
93
  return @stable_branch
67
94
  end
68
95
  def stable_tag
@@ -75,5 +102,32 @@ module BB
75
102
  def verify_stable_env_exists
76
103
  return @stable_source.empty? ? false : true
77
104
  end
105
+ # tag是否存在
106
+ def verify_tag_exists
107
+ tag = stable_tag
108
+ if tag
109
+ cachePath = @cache.cachePath
110
+ # result = system "cd #{cachePath}; git tag"
111
+ result = `cd #{cachePath}; git tag`
112
+ puts "verify_tag_exists:#{result}".red
113
+ return result.split("\n").include?(tag)
114
+ end
115
+ return false
116
+ end
117
+ # 分支是否存在
118
+ def verify_branch_exists
119
+ branch = stable_branch
120
+ if branch
121
+ cachePath = @cache.cachePath
122
+ # result = system "cd #{cachePath}; git tag"
123
+ branchs = `cd #{cachePath}; git branch -a`
124
+ if branchs
125
+ branchs = branchs.split("\n")
126
+ return branchs.include?(branch) || branchs.include?(' remotes/origin/' + branch) || branchs.include?('remotes/origin/' + branch)
127
+ end
128
+ puts "verify_branch_exists:#{branchs}".red
129
+ end
130
+ return false
131
+ end
78
132
  end
79
133
  end
@@ -42,6 +42,7 @@ end
42
42
 
43
43
  $podStartTime = 0
44
44
  $podEndTime = 0
45
+ $source_manager = nil
45
46
 
46
47
  module BB
47
48
 
@@ -49,8 +50,7 @@ module BB
49
50
  begin
50
51
  $podStartTime = Time.new
51
52
  puts "[PodAssistant] plugin hook pre_install".yellow
52
- env = BB::StableEnv.new()
53
- env.system_clone_stable_git # 自动拉取远端git仓库数据
53
+ $source_manager = BB::SourceManager.new() # 自动拉取远端git仓库数据
54
54
  if $pluginIsVerbose == true
55
55
  # home路径下是否存在.AllPodsTimeAndSize.csv的隐藏文件
56
56
  if File.exist?("#{Dir.home}/.AllPodsTimeAndSize.csv")
@@ -68,9 +68,8 @@ module BB
68
68
  end
69
69
  Pod::HooksManager.register("cocoapods-bb-PodAssistant", :post_install) do |installer|
70
70
  begin
71
- source_manager = BB::SourceManager.new()
72
71
  # 生成本地yml配置
73
- source_manager.generate_localStable
72
+ $source_manager.generate_localStable
74
73
  $podEndTime = Time.new
75
74
  puts "[PodAssistant] plugin hook post_install".yellow
76
75
  puts "[PodAssistant] pod库下载耗时 GitCloneAllSize: #{$gitAllSize} M GitCloneAllTime: #{$cloneAllTime} S CDNDownloadAllSize: #{$pluginCurrentZipAllSize} M CDNAllTime: #{$downloadAllTime} S CDNDownloadAllTime: #{$cdnDownloadAllTime} S CDNUnzipAllTime: #{$cdnUnZipAllTime} S"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-bb-PodAssistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - humin