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