cocoapods-bb-PodAssistant 0.3.10.0 → 0.3.11.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: e69481b486b0df554df985240cca0dcd6215a487c3fe900c28b9b7414299a48c
4
- data.tar.gz: c24fa5ab6855c6175c5fd457180e3be1c4fe00e04bb62012e643855d4713f499
3
+ metadata.gz: c64174155b43b25df889bb156ee02467411ce11c89cf2ddb2e9471f8aa675fe2
4
+ data.tar.gz: fcd75f2accb25d16a75ed2ea6d91fbbc2683632a528048b3a73c1aec8e94cb39
5
5
  SHA512:
6
- metadata.gz: '098cb75784f415fdf27654d686f37284a1739452f64eab225c93742aa480fcd3538631acce9c7763bd9cb3a4c17df656dc4d753fb9b83c9a4d5c9489f019956a'
7
- data.tar.gz: 78b051ba39cddd6893104db53e745193e5c5d9dfa4567bd9ac2394cc364eb8fced1afb1f0163b240af076cfff938dedaecea86591dd190d351c7d6f035fbe48c
6
+ metadata.gz: 1d15a10db7b21dae333ff26d0358633ab7bf92032c44188857d9c4db6adc358602fc5a32a82a5158809f3033ee2a75c8a0c3356de28f1e1666f77eac747e14fa
7
+ data.tar.gz: 7be09e5bf0ad8a9a2489699a4c3be1c1009aaf0bf807fa30acc67f07e0b2fc4105ea2b3b03cac5e76e7caf3cc8b65ceca77d0a26a28499f04d322c599fc07a07
@@ -1,19 +1,61 @@
1
+ require 'cocoapods-bb-PodAssistant/config/json_parser'
2
+
1
3
  module BB
2
4
  class DataConfig
3
5
  def self.config
4
6
  @config ||= DataConfig.new
5
7
  end
6
8
 
9
+ def initialize()
10
+ file_path = customConfigPath
11
+ if file_exists?(customConfigPath)
12
+ puts "开始解析打包机自定义配置 json:#{file_path}".yellow
13
+ json_parser = BB::JsonParser.new(file_path)
14
+ @json_data = json_parser.get_json_data
15
+ puts "json数据:#{@json_data}"
16
+ end
17
+ end
18
+
19
+ #与打包机约定自定义配置文件
20
+ def customConfigPath
21
+ return "#{Dir.pwd}/bbCustomConfig.json" # 存放工程目录下
22
+ end
23
+
24
+ # 提供给业务方的获取 JSON 数据方法
25
+ def get_custom_json_data
26
+ return {} unless @json_data
27
+ @json_data
28
+ end
29
+
30
+ # 检查文件是否存在
31
+ def file_exists?(file_path)
32
+ File.exist?(file_path)
33
+ end
34
+
7
35
  # 需要过滤忽略组件
8
36
  def ignore_dependencies_pod_names
9
- puts "<===获取业务方配置过滤组件数据:#{@ignore_pods_list}".yellow
37
+ puts "<===获取业务方配置过滤组件数据:#{@ignore_pods_list} 打包机自定义配置数据:#{@json_data}".yellow
10
38
  return @ignore_pods_list
11
39
  end
12
-
40
+
13
41
  # 配置过滤忽略组件
14
42
  def set_ignore_dependencies_pod_names(pods=[])
15
- puts "==>业务方配置需要过滤组件数据:#{pods} cls:#{pods.class}".yellow
16
- @ignore_pods_list=pods
43
+ @ignore_pods_list = pods
44
+ # puts "==>业务方配置需要过滤组件数据:#{pods} cls:#{pods.class}".yellow
45
+ # json_data = get_custom_json_data
46
+ # if json_data.nil? || json_data.empty?
47
+ # @ignore_pods_list = pods
48
+ # else
49
+ # whitelist_pods=[]
50
+ # pods.each do |pod_name|
51
+ # data = json_data[pod_name]
52
+ # if data.nil? || data.empty?
53
+ # whitelist_pods.push(pod_name)
54
+ # end
55
+ # end
56
+ # puts "==>修正后需要过滤组件数据:#{whitelist_pods} cls:#{whitelist_pods.class}".green
57
+ # @ignore_pods_list = whitelist_pods
58
+ # end
17
59
  end
18
60
  end
19
61
  end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ module BB
4
+ class JsonParser
5
+ attr_reader :json_data
6
+
7
+ # 初始化,读取并解析 JSON 文件
8
+ def initialize(file_path)
9
+ @file_path = file_path
10
+ @json_data = read_json
11
+ end
12
+
13
+ # 读取并解析 JSON 文件
14
+ def read_json
15
+ begin
16
+ file_content = File.read(@file_path)
17
+ JSON.parse(file_content)
18
+ rescue Errno::ENOENT
19
+ puts "错误:找不到文件 #{@file_path}"
20
+ nil
21
+ rescue JSON::ParserError
22
+ puts "错误:JSON 解析失败,请检查文件格式"
23
+ nil
24
+ end
25
+ end
26
+
27
+ # 遍历 JSON 并返回 key-value 结构
28
+ def traverse_json(data = @json_data, prefix = "", result = {})
29
+ return result unless data
30
+
31
+ case data
32
+ when Hash
33
+ data.each do |key, value|
34
+ traverse_json(value, "#{prefix}#{key}.", result)
35
+ end
36
+ when Array
37
+ data.each_with_index do |value, index|
38
+ traverse_json(value, "#{prefix}[#{index}].", result)
39
+ end
40
+ else
41
+ result[prefix.chomp('.')] = data
42
+ end
43
+
44
+ result
45
+ end
46
+
47
+ # 提供给业务方的获取 JSON 数据方法
48
+ def get_json_data
49
+ return {} unless @json_data
50
+ traverse_json
51
+ end
52
+ end
53
+ end
@@ -576,6 +576,22 @@ module BB
576
576
  return (has_include_subspec(podName) && podName.include?("#{podCoreName}/"))
577
577
  end
578
578
 
579
+ # 更新自定义pod组件数据
580
+ def update_custom_podmodules(json_data)
581
+ if json_data.nil? || json_data.empty?
582
+ puts ""
583
+ else
584
+ puts "动态更新本地组件:#{json_data}".yellow
585
+ if json_data.is_a?(Hash)
586
+ local_stable_data = fetch_local_stable_datas # 本地stable配置
587
+ json_data.each do |key, value|
588
+ local_stable_data[key] = value
589
+ end
590
+ puts "[PodAssistant] 更新本地stable数据".yellow
591
+ update_localstable_datas(local_stable_data)
592
+ end
593
+ end
594
+ end
579
595
  # 更新单个pod组件
580
596
  def update_podmodules(pod_lists)
581
597
  local_stable_data = fetch_local_stable_datas # 本地stable配置
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBbPodassistant
2
- VERSION = "0.3.10.0"
2
+ VERSION = "0.3.11.0"
3
3
  end
@@ -24,7 +24,10 @@ module BB
24
24
  # ignore_dependencies_pod_names 过滤组件,不受stable版本控制
25
25
  def initialize(all_modules, member_modules = {}, member_configs = [], ignore_local_stable = false, skip_stable_check = false, ignore_dependencies_pod_names=[])
26
26
  @source_manager = BB::SourceManager.new()
27
- BB::DataConfig.config.set_ignore_dependencies_pod_names(ignore_dependencies_pod_names)
27
+ config = BB::DataConfig.config
28
+ config.set_ignore_dependencies_pod_names(ignore_dependencies_pod_names)
29
+ # # 打包机支持自定义配置,解决开发环境组件动态更新问题
30
+ # @source_manager.update_custom_podmodules(config.get_custom_json_data)
28
31
  #加载远程稳定仓库 和本地podfile 指定的仓库进行合并
29
32
  if skip_stable_check == true
30
33
  # 过滤带:remove数据
@@ -314,6 +317,19 @@ module BB
314
317
  else
315
318
  puts "[PodAssistant] 本地stable数据无变化<===完成".yellow
316
319
  end
320
+ config = BB::DataConfig.config
321
+ json_data = config.get_custom_json_data
322
+ if json_data.nil? || json_data.empty?
323
+ puts ""
324
+ else
325
+ puts "打包后台配置更新自定义组件配置数据:#{json_data}".yellow
326
+ if json_data.is_a?(Hash)
327
+ json_data.each do |key, value|
328
+ stable_hash[key] = value
329
+ puts "=====动态更新组件-#{key}:#{value} 替换版本完成====="
330
+ end
331
+ end
332
+ end
317
333
  # puts "[PodAssistant] stable_hash:#{stable_hash}".red
318
334
  stable_specs = []
319
335
  stable_hash.each do |name,pod|
@@ -1,20 +1,40 @@
1
1
  require 'cocoapods/podfile'
2
2
  require 'cocoapods-core/podfile/dsl'
3
+ require 'cocoapods-bb-PodAssistant/helpers/swiftlint_path_helper'
3
4
  require 'uri'
4
5
  require 'yaml'
5
6
  require 'fileutils'
6
7
 
7
8
  module BB
8
9
  class SwiftlintManager
10
+
11
+ @update_config = false
12
+
9
13
  def initialize()
10
- update_swiftlint_file()
11
- update_swiftlint_script()
12
- update_swiftlint_gitignore()
14
+ remove_swiftlint_path()
15
+ # 已安装过run swiftlint脚本将强制更新
16
+ update_swiftlint_script(true)
17
+ end
18
+
19
+ def update_swiftlint_config()
20
+ # 单次运行过程中只安装或更新一次
21
+ if !@update_config
22
+ @update_config = true
23
+ update_swiftlint_file()
24
+ update_swiftlint_script()
25
+ update_swiftlint_gitignore()
26
+ end
13
27
  end
14
28
 
15
29
  # 写入路径到swiftlint文件
16
- def swiftlint_from_module(path)
17
- write_swiftlint_included(path)
30
+ def swiftlint_from_module(name, lib_path)
31
+ # 查询真实路径
32
+ path_list = SwiftlintFilesHelper.query_file_path(name, lib_path)
33
+ unless path_list.empty?
34
+ path_list.each do | path |
35
+ write_swiftlint_included(path)
36
+ end
37
+ end
18
38
  end
19
39
 
20
40
  private def swiftlint_tag()
@@ -79,6 +99,32 @@ module BB
79
99
  end
80
100
  end
81
101
 
102
+ # 删除路临时路径文件
103
+ private def remove_swiftlint_path()
104
+ file_path = getSwiftlintFilepath()
105
+ if File.exist?(file_path)
106
+ begin
107
+ # 检查文件是否存在
108
+ if File.exist?(file_path)
109
+ # 尝试删除文件
110
+ File.delete(file_path)
111
+ # puts "文件已成功删除: #{file_path}"
112
+ else
113
+ # puts "文件不存在: #{file_path}"
114
+ end
115
+ rescue Errno::EACCES => e
116
+ # 处理权限错误
117
+ puts "权限不足,无法删除文件: #{e.message}"
118
+ rescue Errno::ENOENT => e
119
+ # 文件不存在错误已经被上面的 if File.exist? 处理了,这里可以省略或用于其他未预见的情况
120
+ puts "尝试删除不存在的文件: #{e.message}"
121
+ rescue => e
122
+ # 处理所有其他类型的异常
123
+ puts "删除文件时发生错误: #{e.message}"
124
+ end
125
+ end
126
+ end
127
+
82
128
  # 写入swiftlint临时文件gitignore过滤规则
83
129
  private def update_swiftlint_gitignore()
84
130
  files_to_ignore = [
@@ -293,7 +339,7 @@ module BB
293
339
  end
294
340
 
295
341
  # 更新script脚本
296
- def update_swiftlint_script()
342
+ def update_swiftlint_script(force = false)
297
343
 
298
344
  project_path = find_xcodeproj_file()
299
345
  if project_path.nil?
@@ -316,7 +362,7 @@ module BB
316
362
  existing_script = mainTarget.shell_script_build_phases.find do |phase|
317
363
  phase.name == xcode_script_name
318
364
  end
319
-
365
+
320
366
  if existing_script
321
367
  script_content = existing_script.shell_script
322
368
  local_script_version = get_script_version(script_content)
@@ -330,7 +376,7 @@ module BB
330
376
  existing_script.shell_script = File.read(cache_script_path)
331
377
  project.save
332
378
  end
333
- else
379
+ elsif !force
334
380
  puts "#{swiftlint_tag} Xcode工程配置中的不存在#{xcode_script_name}脚本,更新脚本".green
335
381
  new_script = mainTarget.new_shell_script_build_phase(xcode_script_name)
336
382
  new_script.shell_script = File.read(cache_script_path)
@@ -0,0 +1,175 @@
1
+ require 'xcodeproj'
2
+ require 'cocoapods' # 加载 CocoaPods 核心库
3
+
4
+ module BB
5
+ class SwiftlintFilesHelper
6
+ # 类变量存储所有subspecs信息
7
+ @@subspecs_info = {}
8
+
9
+ # 获取组件subspecs路径
10
+ def self.extract_subspecs(spec, parent_name = nil, lib_name = nil)
11
+ subspecs_info = {}
12
+
13
+ full_name = parent_name ? "#{parent_name}/#{spec.name.split('/').last}" : spec.name
14
+ source_files = spec.attributes_hash['source_files']
15
+
16
+ info_list = subspecs_info[full_name]
17
+ if info_list.nil?
18
+ info_list = []
19
+ end
20
+
21
+ # 处理source_files路径
22
+ if source_files.is_a?(String)
23
+ info_list << source_files
24
+ elsif source_files.is_a?(Array)
25
+ info_list = info_list | source_files
26
+ end
27
+
28
+ # 处理dependency内部引用路径
29
+ spec.dependencies.each do | dependency |
30
+ dep_str = dependency.to_s
31
+ # 检查依赖项是否匹配指定的库名
32
+ if dep_str.start_with?(lib_name)
33
+ info_list << dep_str
34
+ end
35
+ end
36
+
37
+ unless info_list.empty?
38
+ subspecs_info[full_name] = info_list if info_list
39
+ end
40
+
41
+ spec.subspecs.each do |subspec|
42
+ subspecs_info.merge!(extract_subspecs(subspec, full_name, lib_name))
43
+ end
44
+
45
+ return subspecs_info
46
+ end
47
+
48
+ def self.parse_podspec(file_path)
49
+ # Load the podspec file
50
+ spec = Pod::Specification.from_file(file_path)
51
+ spec_name = spec.attributes_hash['name']
52
+
53
+ # Extract subspecs information
54
+ subspecs_info = extract_subspecs(spec, nil, spec_name)
55
+
56
+ default_subspecs = spec.attributes_hash['default_subspecs']
57
+
58
+ # 处理默认引用
59
+ if default_subspecs.is_a?(String)
60
+ default_name = File.join(spec_name, default_subspecs)
61
+ info_list = subspecs_info[default_name]
62
+ subspecs_info[spec_name] = info_list if info_list
63
+ elsif default_subspecs.is_a?(Array)
64
+ default_list = []
65
+ default_subspecs.each do | name |
66
+ default_name = File.join(spec_name, name)
67
+ info_list = subspecs_info[default_name]
68
+ if info_list.is_a?(Array) && !info_list.empty
69
+ default_list = default_list | info_list
70
+ end
71
+ end
72
+ unless default_list.empty
73
+ subspecs_info[spec_name] = default_list if default_list
74
+ end
75
+ end
76
+
77
+ return subspecs_info
78
+ end
79
+
80
+ # 获取真正路径
81
+ def self.sanitize_path(path, lib_path)
82
+
83
+ return nil if path.nil? || lib_path.nil?
84
+
85
+ real_path = path.dup # 创建副本以避免修改原始数据
86
+ # 去除 *.{...} 或 **/*.{...} 等文件匹配模式
87
+ real_path.gsub!(%r{\*\.(\{\w+(,\w+)*\}|)}, "") # 匹配 *.{ext} 或 *.{}
88
+ real_path.gsub!(%r{/\*\*/}, "") # 匹配 /**/
89
+ real_path.gsub!(%r{\*}, "") # 匹配单独的 *
90
+
91
+ # 如果路径不以斜杠结尾,则添加斜杠
92
+ real_path += '/' unless real_path.end_with?('/')
93
+
94
+ # 去除多余的斜杠(如果有)
95
+ real_path.squeeze!('/')
96
+
97
+ # 去除末尾的多余斜杠
98
+ real_path.chomp!('/') if real_path != '/'
99
+
100
+ file_path = File.join(lib_path, real_path)
101
+ if File.exist?(file_path)
102
+ return file_path
103
+ end
104
+
105
+ return nil
106
+ end
107
+
108
+ def self.extract_subspec_real_paths(name, lib_path)
109
+
110
+ return nil if @@subspecs_info.nil?
111
+
112
+ path_list = @@subspecs_info[name]
113
+ realPaths = []
114
+ unless path_list.nil?
115
+ path_list.each do | path |
116
+ realPath = sanitize_path(path, lib_path)
117
+ if realPath.nil? && path != nil && path.to_s.length > 0
118
+ paths = extract_subspec_real_paths(path, lib_path)
119
+ realPaths = realPaths | paths
120
+ else
121
+ # 不存在则添加
122
+ unless realPaths.include?(realPath)
123
+ realPaths << realPath
124
+ end
125
+ end
126
+ end
127
+ end
128
+ return realPaths
129
+ end
130
+
131
+ # 查询路径
132
+ def self.query_file_path(name, lib_path)
133
+
134
+ return nil if name.nil? || lib_path.nil?
135
+
136
+ if @@subspecs_info[name].nil?
137
+ podspec_path = find_first_with_suffix(lib_path, ".podspec")
138
+ unless podspec_path.nil?
139
+ info = parse_podspec(podspec_path)
140
+ if @@subspecs_info.nil?
141
+ @@subspecs_info = info
142
+ else
143
+ @@subspecs_info.merge!(info) { |key, oldval, newval|
144
+ # 如果键对应的值也是哈希,则可以递归合并
145
+ oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.merge(newval) : newval
146
+ }
147
+ end
148
+ end
149
+ end
150
+
151
+ return extract_subspec_real_paths(name, lib_path)
152
+ end
153
+
154
+ # 类方法:根据后缀递归查找文件或目录
155
+ def self.find_first_with_suffix(directory, suffix)
156
+ # 检查目录是否存在
157
+ unless Dir.exist?(directory)
158
+ puts "目录 #{directory} 不存在"
159
+ return nil
160
+ end
161
+
162
+ # 遍历目录下的所有文件和子目录
163
+ Find.find(directory) do |path|
164
+ # 如果是文件或目录且以给定后缀结尾,则返回其完整路径
165
+ if (File.file?(path) || File.directory?(path)) && File.basename(path).end_with?(suffix)
166
+ return path
167
+ end
168
+ end
169
+
170
+ # 如果没有找到匹配项
171
+ puts "未找到以 '#{suffix}' 结尾的文件或目录"
172
+ nil
173
+ end
174
+ end
175
+ end
@@ -175,10 +175,10 @@ module Pod
175
175
  swiftlint = source_module[:swiftlint]
176
176
  swiftlintKey = :swiftlint if swiftlint.to_s.length > 0
177
177
  if swiftlint != nil && swiftlintKey.length > 0
178
- if @swiftlint.nil?
179
- @swiftlint = BB::SwiftlintManager.new()
178
+ unless @swiftlint.nil?
179
+ @swiftlint.update_swiftlint_config()
180
+ @swiftlint.swiftlint_from_module(source_module[:name], path)
180
181
  end
181
- @swiftlint.swiftlint_from_module(path)
182
182
  end
183
183
  end
184
184
 
@@ -295,6 +295,11 @@ module Pod
295
295
  linkageKey = :linkage if linkage.to_s.length > 0
296
296
  linkagesKey = :linkages if linkages.to_s.length > 0
297
297
 
298
+ # 初始化swiftlint,清空上次podin路径且强制更新script脚本
299
+ if @swiftlint.nil?
300
+ @swiftlint = BB::SwiftlintManager.new()
301
+ end
302
+
298
303
  case method
299
304
  when DEFAULT
300
305
  # 根据参数判断method
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-bb-PodAssistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10.0
4
+ version: 0.3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - humin
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-23 00:00:00.000000000 Z
10
+ date: 2025-02-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: cocoapods-core
@@ -169,6 +169,7 @@ files:
169
169
  - lib/cocoapods-bb-PodAssistant/command/stable/update.rb
170
170
  - lib/cocoapods-bb-PodAssistant/config/cache_path.rb
171
171
  - lib/cocoapods-bb-PodAssistant/config/data_config.rb
172
+ - lib/cocoapods-bb-PodAssistant/config/json_parser.rb
172
173
  - lib/cocoapods-bb-PodAssistant/config/source_manager.rb
173
174
  - lib/cocoapods-bb-PodAssistant/config/stable_source.rb
174
175
  - lib/cocoapods-bb-PodAssistant/config/stable_specs.rb
@@ -180,6 +181,7 @@ files:
180
181
  - lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb
181
182
  - lib/cocoapods-bb-PodAssistant/helpers/stable_manager_helper.rb
182
183
  - lib/cocoapods-bb-PodAssistant/helpers/swiftlint_manager_helper.rb
184
+ - lib/cocoapods-bb-PodAssistant/helpers/swiftlint_path_helper.rb
183
185
  - lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb
184
186
  - lib/cocoapods-bb-PodAssistant/native/installer.rb
185
187
  - lib/cocoapods-bb-PodAssistant/podfile.rb