cocoapods-bb-PodAssistant 0.3.9.2 → 0.3.10.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f1db4fab849997bfd3bff5a50ab2c1fb15ad3a476bb5141d51518da03c6448
|
4
|
+
data.tar.gz: 5f8dd3b98bf005ed5f94e1a0b71355cd6ddf2ceb0dbbd0a182d5282bddc75161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd5f80fdd24c8e46ee0592a00e370e4486d9ae7951d015c9a79491493466751049eb0d28419317a2df15ebe41451362eadffaeb0e9f3ee4bf204f01191c41b9c
|
7
|
+
data.tar.gz: d77ff2a1521ee1fa2aff43d579bef4ceab20d71c0e4d955fe5dfdb3f19439f6fafd59f6a0a420a0c9d25a288b4eb9e21375fbc7b44b804b6bff248864d1016e8
|
@@ -0,0 +1,387 @@
|
|
1
|
+
require 'cocoapods/podfile'
|
2
|
+
require 'cocoapods-core/podfile/dsl'
|
3
|
+
require 'cocoapods-bb-PodAssistant/helpers/swiftlint_path_helper'
|
4
|
+
require 'uri'
|
5
|
+
require 'yaml'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module BB
|
9
|
+
class SwiftlintManager
|
10
|
+
|
11
|
+
@update_config = false
|
12
|
+
|
13
|
+
def initialize()
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
# 写入路径到swiftlint文件
|
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
|
38
|
+
end
|
39
|
+
|
40
|
+
private def swiftlint_tag()
|
41
|
+
return "[Swiftlint]"
|
42
|
+
end
|
43
|
+
|
44
|
+
# swiftlint文件名称
|
45
|
+
private def swiftlint_name()
|
46
|
+
return 'swiftlint.yml'
|
47
|
+
end
|
48
|
+
|
49
|
+
# 脚本文件名称
|
50
|
+
private def sh_script_name()
|
51
|
+
return 'runSwiftlint.sh'
|
52
|
+
end
|
53
|
+
|
54
|
+
# 工程内Script名称
|
55
|
+
private def xcode_script_name()
|
56
|
+
return 'Run Swiftlint'
|
57
|
+
end
|
58
|
+
|
59
|
+
# 记录需要swiftlint编译库本地路径文件
|
60
|
+
private def getSwiftlintFilepath()
|
61
|
+
return File.join(Pathname.pwd, ".swiftlint_path.yml")
|
62
|
+
end
|
63
|
+
|
64
|
+
# 下载的yml文件缓存路径
|
65
|
+
private def cocoapods_swiftlint_path()
|
66
|
+
return File.join(ENV['HOME'], '.cache', 'cocoapods-bb-PodAssistant', 'swiftlint', swiftlint_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
# 工程内yml文件路径
|
70
|
+
private def local_swiftlint_path()
|
71
|
+
return File.join(Pathname.pwd, swiftlint_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
# 下载的脚本文件缓存路径
|
75
|
+
private def cocoapods_script_path()
|
76
|
+
return File.join(ENV['HOME'], '.cache', 'cocoapods-bb-PodAssistant', 'swiftlint', sh_script_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
# 创建记录需要swiftlint编译的路径
|
80
|
+
private def create_swiftlint_included()
|
81
|
+
config_path = getSwiftlintFilepath()
|
82
|
+
if File.exist?(config_path)
|
83
|
+
# 如果文件存在,则清空文件内容
|
84
|
+
File.open(config_path, 'w') {} # 打开文件并立即关闭,这将清空文件内容
|
85
|
+
# puts "已清空文件: #{config_path}"
|
86
|
+
else
|
87
|
+
# 如果文件不存在,则创建一个新的空白文件
|
88
|
+
File.new(config_path, 'w')
|
89
|
+
# puts "已创建新的空白文件: #{config_path}"
|
90
|
+
end
|
91
|
+
|
92
|
+
initial_config = <<~YAML
|
93
|
+
# 需参与Swiftlint修复的路径
|
94
|
+
included:
|
95
|
+
YAML
|
96
|
+
# 写入配置到 swiftlint.yml 文件
|
97
|
+
File.open(config_path, 'w') do |file|
|
98
|
+
file.write(initial_config)
|
99
|
+
end
|
100
|
+
end
|
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
|
+
|
128
|
+
# 写入swiftlint临时文件gitignore过滤规则
|
129
|
+
private def update_swiftlint_gitignore()
|
130
|
+
files_to_ignore = [
|
131
|
+
".swiftlint_path.yml",
|
132
|
+
"swiftlint_log.txt"
|
133
|
+
]
|
134
|
+
|
135
|
+
gitignore_path = File.join(Pathname.pwd, ".gitignore")
|
136
|
+
# 检查当前目录.gitignore 文件是否存在
|
137
|
+
if !File.exist?(gitignore_path)
|
138
|
+
gitignore_path = File.join(Pathname.pwd, "../.gitignore")
|
139
|
+
# 检查上级目录.gitignore 文件是否存在
|
140
|
+
if !File.exist?(gitignore_path)
|
141
|
+
# puts "未找到 .gitignore 文件 #{gitignore_path}".green
|
142
|
+
return
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# 读取现有 .gitignore 文件的内容
|
147
|
+
content = File.read(gitignore_path)
|
148
|
+
|
149
|
+
# 需要添加的新行
|
150
|
+
new_entries = []
|
151
|
+
|
152
|
+
# 检查每个需要忽略的文件是否已在 .gitignore 中
|
153
|
+
files_to_ignore.each do |file|
|
154
|
+
unless content.include?(file)
|
155
|
+
new_entries << file
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# 如果有新的忽略项,则追加到 .gitignore 文件
|
160
|
+
if new_entries.any?
|
161
|
+
File.open(gitignore_path, 'a') do |file|
|
162
|
+
file.puts "\n# swiftlint临时文件"
|
163
|
+
new_entries.each do |entry|
|
164
|
+
file.puts entry
|
165
|
+
# puts "已将 '#{entry}' 添加到 .gitignore".green
|
166
|
+
end
|
167
|
+
end
|
168
|
+
else
|
169
|
+
# puts ".gitignore 已经包含了所有需要的忽略规则".green
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
private def writePath(path)
|
174
|
+
config_path = getSwiftlintFilepath()
|
175
|
+
File.open(config_path, 'a') do |file|
|
176
|
+
# puts "写入路径:#{path}".red
|
177
|
+
file.puts " - "+path
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# 写入个人配置路径
|
182
|
+
private def write_swiftlint_included(path)
|
183
|
+
|
184
|
+
config_path = getSwiftlintFilepath()
|
185
|
+
if !File.exist?(config_path)
|
186
|
+
create_swiftlint_included()
|
187
|
+
end
|
188
|
+
|
189
|
+
content = File.read(config_path)
|
190
|
+
configs = YAML.safe_load(content) || {}
|
191
|
+
|
192
|
+
# included数组不存在数据
|
193
|
+
if configs['included'].nil?
|
194
|
+
writePath(path)
|
195
|
+
else
|
196
|
+
included_paths = configs['included'].map(&:strip)
|
197
|
+
if included_paths.include?(path.strip)
|
198
|
+
# 路径已添加,则忽略
|
199
|
+
return
|
200
|
+
end
|
201
|
+
writePath(path)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# 查找.xcodeproj文件
|
206
|
+
def find_xcodeproj_file()
|
207
|
+
file_extension = '.xcodeproj'
|
208
|
+
dir_path = Pathname.pwd
|
209
|
+
|
210
|
+
unless Dir.exist?(dir_path)
|
211
|
+
# puts "目录 '#{dir_path}' 不存在"
|
212
|
+
return nil
|
213
|
+
end
|
214
|
+
|
215
|
+
# 遍历当前目录下的所有文件和目录
|
216
|
+
found_file = nil
|
217
|
+
Dir.foreach(dir_path) do |entry|
|
218
|
+
# 跳过 '.' 和 '..' 目录
|
219
|
+
next if entry == '.' || entry == '..'
|
220
|
+
|
221
|
+
# 构造完整路径
|
222
|
+
full_path = File.join(dir_path, entry)
|
223
|
+
|
224
|
+
# 检查是否为文件以及是否以指定后缀结尾
|
225
|
+
if File.directory?(full_path) && entry.end_with?(file_extension)
|
226
|
+
found_file = full_path
|
227
|
+
break # 找到第一个匹配项后退出循环
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
return found_file
|
232
|
+
end
|
233
|
+
|
234
|
+
# 获取yml文件版本号
|
235
|
+
private def get_swiftlint_version(config_path)
|
236
|
+
if File.exist?(config_path)
|
237
|
+
# 读取现有的 swiftlint.yml 文件
|
238
|
+
config_content = YAML.load_file(config_path)
|
239
|
+
# 获取 included 路径列表,如果不存在则初始化为空数组
|
240
|
+
product_custom = config_content['product_custom'] || []
|
241
|
+
|
242
|
+
# 提取版本号
|
243
|
+
version_from_yml = nil
|
244
|
+
product_custom.each do |item|
|
245
|
+
if item.start_with?('version-')
|
246
|
+
version_from_yml = item.split('-').last
|
247
|
+
break
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
unless version_from_yml
|
252
|
+
# puts "未能在配置文件中找到有效的版本号"
|
253
|
+
return nil
|
254
|
+
end
|
255
|
+
|
256
|
+
# puts "从配置文件读取到的版本号为: #{version_from_yml}"
|
257
|
+
return version_from_yml
|
258
|
+
end
|
259
|
+
|
260
|
+
return nil
|
261
|
+
end
|
262
|
+
|
263
|
+
# 是否更新yml文件
|
264
|
+
private def is_update_swiftlint()
|
265
|
+
local_path = local_swiftlint_path()
|
266
|
+
cache_path = cocoapods_swiftlint_path()
|
267
|
+
|
268
|
+
remote_version = get_swiftlint_version(cache_path)
|
269
|
+
if remote_version.nil?
|
270
|
+
# puts "远端配置文件中的版本未找到,无需更新"
|
271
|
+
return false
|
272
|
+
end
|
273
|
+
|
274
|
+
if File.exist?(local_path)
|
275
|
+
# 读取本地swiftlint.yml 文件
|
276
|
+
config_content = YAML.load_file(local_path)
|
277
|
+
if config_content['product_custom']&.include?('custom_rules')
|
278
|
+
puts "#{swiftlint_tag} 检测到 'custom_rules' 字段,配置文件不会被更新".green
|
279
|
+
return false
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
local_version = get_swiftlint_version(local_path)
|
284
|
+
if local_version.nil? || Gem::Version.new(local_version) < Gem::Version.new(remote_version)
|
285
|
+
if local_version.nil?
|
286
|
+
puts "#{swiftlint_tag} 工程内无swiftlint规则文件 或 无版本,更新规则文件".green
|
287
|
+
else
|
288
|
+
puts "#{swiftlint_tag} 工程内swiftlint规则文件配置版本:#{local_version} 小于 远端版本:#{remote_version},更新规则文件".green
|
289
|
+
end
|
290
|
+
return true
|
291
|
+
end
|
292
|
+
|
293
|
+
# puts "配置文件中的版本已是最新,无需更新"
|
294
|
+
return false
|
295
|
+
end
|
296
|
+
|
297
|
+
# 更新swiftlint文件
|
298
|
+
private def update_swiftlint_file()
|
299
|
+
if !is_update_swiftlint()
|
300
|
+
return
|
301
|
+
end
|
302
|
+
|
303
|
+
cache_path = cocoapods_swiftlint_path()
|
304
|
+
local_path = local_swiftlint_path()
|
305
|
+
|
306
|
+
unless File.exist?(cache_path)
|
307
|
+
puts "#{swiftlint_tag} #{swiftlint_name}源文件不存在: #{cache_path}"
|
308
|
+
exit
|
309
|
+
end
|
310
|
+
|
311
|
+
# 复制文件并覆盖已存在的文件
|
312
|
+
begin
|
313
|
+
FileUtils.cp(cache_path, local_path) # force: true 参数确保覆盖同名文件
|
314
|
+
puts "#{swiftlint_tag} #{swiftlint_name}已成功复制到: #{local_path}".green
|
315
|
+
rescue => e
|
316
|
+
puts "#{swiftlint_tag} #{swiftlint_name}复制失败: #{e.message}".green
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# 获取远端script脚本版本
|
321
|
+
def cocoapods_script_version(script_path)
|
322
|
+
unless File.exist?(script_path)
|
323
|
+
return nil
|
324
|
+
end
|
325
|
+
|
326
|
+
script_content = File.read(script_path)
|
327
|
+
return get_script_version(script_content)
|
328
|
+
end
|
329
|
+
|
330
|
+
# 获取script脚本版本
|
331
|
+
def get_script_version(script_content)
|
332
|
+
# 使用正则表达式匹配本地脚本中的 SCRIPT_VERSION 字段
|
333
|
+
if script_content =~ /SCRIPT_VERSION=['"]([^'"]+)['"]/
|
334
|
+
local_script_version = $1
|
335
|
+
return local_script_version
|
336
|
+
end
|
337
|
+
|
338
|
+
return nil
|
339
|
+
end
|
340
|
+
|
341
|
+
# 更新script脚本
|
342
|
+
def update_swiftlint_script(force = false)
|
343
|
+
|
344
|
+
project_path = find_xcodeproj_file()
|
345
|
+
if project_path.nil?
|
346
|
+
puts "#{swiftlint_tag} 未找到 .xcodeproj工程文件"
|
347
|
+
return
|
348
|
+
end
|
349
|
+
|
350
|
+
cache_script_path = cocoapods_script_path()
|
351
|
+
cache_script_version = cocoapods_script_version(cache_script_path)
|
352
|
+
if cache_script_version.nil?
|
353
|
+
# puts "远端#{sh_script_name}不存在: #{cache_script_path}"
|
354
|
+
return
|
355
|
+
end
|
356
|
+
# puts "远端#{sh_script_name}版本号:#{cache_script_version}"
|
357
|
+
|
358
|
+
project = Xcodeproj::Project.open(project_path)
|
359
|
+
mainTarget = project.targets.first # 取出第一个target
|
360
|
+
|
361
|
+
# 检查是否已经存在名为“Run SwiftLint”的Run Script
|
362
|
+
existing_script = mainTarget.shell_script_build_phases.find do |phase|
|
363
|
+
phase.name == xcode_script_name
|
364
|
+
end
|
365
|
+
|
366
|
+
if existing_script
|
367
|
+
script_content = existing_script.shell_script
|
368
|
+
local_script_version = get_script_version(script_content)
|
369
|
+
if local_script_version.nil? || Gem::Version.new(local_script_version) < Gem::Version.new(cache_script_version)
|
370
|
+
if local_script_version.nil?
|
371
|
+
puts "#{swiftlint_tag} Xcode工程配置中的不存在#{xcode_script_name} 或 无版本,更新#{xcode_script_name}脚本".green
|
372
|
+
else
|
373
|
+
puts "#{swiftlint_tag} Xcode工程配置#{xcode_script_name}版本:#{local_script_version} 小于 远端版本:#{cache_script_version},更新#{xcode_script_name}脚本".green
|
374
|
+
end
|
375
|
+
|
376
|
+
existing_script.shell_script = File.read(cache_script_path)
|
377
|
+
project.save
|
378
|
+
end
|
379
|
+
elsif !force
|
380
|
+
puts "#{swiftlint_tag} Xcode工程配置中的不存在#{xcode_script_name}脚本,更新脚本".green
|
381
|
+
new_script = mainTarget.new_shell_script_build_phase(xcode_script_name)
|
382
|
+
new_script.shell_script = File.read(cache_script_path)
|
383
|
+
project.save
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
@@ -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
|
@@ -5,6 +5,7 @@ require 'cocoapods-bb-PodAssistant'
|
|
5
5
|
require 'cocoapods-bb-PodAssistant/helpers/pod_module_helper'
|
6
6
|
require 'cocoapods-bb-PodAssistant/helpers/stable_manager_helper'
|
7
7
|
require 'cocoapods-bb-PodAssistant/config/source_manager'
|
8
|
+
require 'cocoapods-bb-PodAssistant/helpers/swiftlint_manager_helper'
|
8
9
|
|
9
10
|
# 参数
|
10
11
|
# :name, :names,
|
@@ -148,6 +149,7 @@ module Pod
|
|
148
149
|
:configurations,
|
149
150
|
:linkage,
|
150
151
|
:linkages,
|
152
|
+
:swiftlint,
|
151
153
|
]
|
152
154
|
end
|
153
155
|
|
@@ -168,6 +170,18 @@ module Pod
|
|
168
170
|
|
169
171
|
end
|
170
172
|
|
173
|
+
# 处理swiftlint
|
174
|
+
def swiftlint_from_module(path, source_module)
|
175
|
+
swiftlint = source_module[:swiftlint]
|
176
|
+
swiftlintKey = :swiftlint if swiftlint.to_s.length > 0
|
177
|
+
if swiftlint != nil && swiftlintKey.length > 0
|
178
|
+
unless @swiftlint.nil?
|
179
|
+
@swiftlint.update_swiftlint_config()
|
180
|
+
@swiftlint.swiftlint_from_module(source_module[:name], path)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
171
185
|
# 根据请求方式调整配置 如果明确指定了方法 则使用方法 否则 使用默认方法(如果本地存在对应的项目地址就请求,否则就请求git仓库,否则报错)
|
172
186
|
def module_with_method(method=DEFAULT, source_module, current_member)
|
173
187
|
|
@@ -281,6 +295,11 @@ module Pod
|
|
281
295
|
linkageKey = :linkage if linkage.to_s.length > 0
|
282
296
|
linkagesKey = :linkages if linkages.to_s.length > 0
|
283
297
|
|
298
|
+
# 初始化swiftlint,清空上次podin路径且强制更新script脚本
|
299
|
+
if @swiftlint.nil?
|
300
|
+
@swiftlint = BB::SwiftlintManager.new()
|
301
|
+
end
|
302
|
+
|
284
303
|
case method
|
285
304
|
when DEFAULT
|
286
305
|
# 根据参数判断method
|
@@ -293,6 +312,7 @@ module Pod
|
|
293
312
|
if ( path != nil && path.length > 0 )
|
294
313
|
if File.exist?(path)
|
295
314
|
pod "#{name}", :path => "#{path}", :inhibit_warnings => inhibit_warnings_variable , :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
|
315
|
+
swiftlint_from_module(path, source_module)
|
296
316
|
end
|
297
317
|
else
|
298
318
|
module_with_method(REMOTE_VERSION, source_module, current_member)
|
@@ -427,4 +447,4 @@ module Pod
|
|
427
447
|
end
|
428
448
|
end
|
429
449
|
end
|
430
|
-
end
|
450
|
+
end
|
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.
|
4
|
+
version: 0.3.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- humin
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: cocoapods-core
|
@@ -179,6 +179,8 @@ files:
|
|
179
179
|
- lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb
|
180
180
|
- lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb
|
181
181
|
- lib/cocoapods-bb-PodAssistant/helpers/stable_manager_helper.rb
|
182
|
+
- lib/cocoapods-bb-PodAssistant/helpers/swiftlint_manager_helper.rb
|
183
|
+
- lib/cocoapods-bb-PodAssistant/helpers/swiftlint_path_helper.rb
|
182
184
|
- lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb
|
183
185
|
- lib/cocoapods-bb-PodAssistant/native/installer.rb
|
184
186
|
- lib/cocoapods-bb-PodAssistant/podfile.rb
|