cocoapods-bb-PodAssistant 0.3.8.0 → 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: 591f0737b7cec4e7779d193eb7fa0b9822e1a7017b281580048c577383193bd2
4
- data.tar.gz: 3cf7f1112f2a31fef0fd2d2816d2a2e5b23932988a24722b8273b9dd4c47dd33
3
+ metadata.gz: e69481b486b0df554df985240cca0dcd6215a487c3fe900c28b9b7414299a48c
4
+ data.tar.gz: c24fa5ab6855c6175c5fd457180e3be1c4fe00e04bb62012e643855d4713f499
5
5
  SHA512:
6
- metadata.gz: 296ee33991c46c0a91c888dc0452055d6462e92cf60fac5d5a06d1a3bb8e3f8d6cdf7aa046b3d7f9a274421c632695f5724be9b4fe1af435ef71e140f2d0f4de
7
- data.tar.gz: efaddedb930bdc695bd1b3e80b8b56e8e66d49d654187cb075f367423763939c2b65945ca50074abc1252ef9ded85955f7f025ca9b99a403584e97b9f39529f0
6
+ metadata.gz: '098cb75784f415fdf27654d686f37284a1739452f64eab225c93742aa480fcd3538631acce9c7763bd9cb3a4c17df656dc4d753fb9b83c9a4d5c9489f019956a'
7
+ data.tar.gz: 78b051ba39cddd6893104db53e745193e5c5d9dfa4567bd9ac2394cc364eb8fced1afb1f0163b240af076cfff938dedaecea86591dd190d351c7d6f035fbe48c
data/README.md CHANGED
@@ -57,4 +57,22 @@ pod stable update [组件名称] --sync
57
57
  * Build the component itself with a static framework
58
58
  ```
59
59
  pod 'xxx', :linkage => :static
60
- ```
60
+ ```
61
+
62
+ ## 可执行文件
63
+
64
+ * Tools工具集使用
65
+
66
+ ```
67
+ bb_tools --help
68
+ ```
69
+
70
+ * pp文件加密
71
+ ```
72
+ match_encrypt [password] [input_path] [output_path]
73
+ ```
74
+
75
+ * pp文件解密
76
+ ```
77
+ match_decrypt [password] [input_path] [output_path]
78
+ ```
data/bin/bb_tools ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'colored2'
4
+ require 'cocoapods-bb-PodAssistant'
5
+
6
+ include GLI::App
7
+
8
+ program_desc '内部命令行工具, 为iOS开发者提供的工具集合'
9
+ version CocoapodsBbPodassistant::VERSION
10
+
11
+ def usage
12
+ puts "USAGE: bb_tools command [args]".yellow
13
+ run(ARGV)
14
+ exit(-1)
15
+ end
16
+
17
+ desc "解析linkmap"
18
+ arg 'LinkMap-normal-arm64.txt'
19
+ command :parse do |c|
20
+ c.action do |global_options, options, args|
21
+ if args.size == 0
22
+ usage
23
+ elsif args.size == 1
24
+ BBItools::LinkMap.parser(args[0])
25
+ else
26
+ BBItools::LinkMap.parser_by_folder(args)
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "在文件夹或文件中查找字符串(或者字符串组)"
32
+ arg 'xxx.txt'
33
+ command :search do |c|
34
+ c.action do |global_options, options, args|
35
+ BBItools::StringSearcher.search_result(args[0],args[1])
36
+ end
37
+ end
38
+ # 查找工程中没有用到的图片
39
+ desc "查找无用图片"
40
+ arg 'xxx.txt'
41
+ command :find do |c|
42
+ c.action do |global_options, options, args|
43
+ BBItools::ImgFinder.find(args[0])
44
+ end
45
+ end
46
+ # 查找Xcode工程中没有用到的类
47
+ desc "查找无用类"
48
+ arg 'xxx.txt'
49
+ command :search_unuse_class do |c|
50
+ c.action do |global_options, options, args|
51
+ BBItools::ClassFinder.search_unuse_class(args)
52
+ end
53
+ end
54
+
55
+ # 计算占用内存大小
56
+ desc "计算文件或者文件夹占用内存大小"
57
+ arg 'xxx.txt'
58
+ command :size_for do |c|
59
+ c.action do |global_options, options, args|
60
+ BBItools::Memory.sizeFor(args)
61
+ end
62
+ end
63
+
64
+ # 查找文件
65
+ desc "查找文件"
66
+ arg 'file name'
67
+ command :search_file do |c|
68
+ c.action do |global_options, options, args|
69
+ BBItools::FileSearcher.searchFile(args)
70
+ end
71
+ end
72
+
73
+ # 统计代码行数
74
+ desc "统计代码行数"
75
+ arg 'file name or folder'
76
+ command :count_code_line do |c|
77
+ c.action do |global_options, options, args|
78
+ BBItools::CodeCouner.count_line(args)
79
+ end
80
+ end
81
+
82
+ #本地commit规范化
83
+ desc "hook本地commit,然后进行规commit lint范化"
84
+ arg 'git项目根目录 or 可空'
85
+ command :lint do |c|
86
+ c.action do |global_options,options, args|
87
+ BBItools::GitSets.commit_msg_init(args)
88
+ end
89
+ end
90
+
91
+ #podfile.lock库平铺
92
+ desc "可以将podfile.lock中所有的依赖平铺至Podifle中"
93
+ arg 'podfile.lock'
94
+ command :podfile_tiled do |c|
95
+ c.action do |global_options,options, args|
96
+ BBItools::PodfileTiled.podfile_tiled(args)
97
+ end
98
+ end
99
+ exit run(ARGV)
@@ -8,4 +8,6 @@ require 'cocoapods-bb-PodAssistant/babybus/stable/podfile-linkline'
8
8
  require 'cocoapods-bb-PodAssistant/command/linkline'
9
9
  require 'cocoapods-bb-PodAssistant/babybus/linkline/target-linkline'
10
10
  require 'cocoapods-bb-PodAssistant/babybus/linkline/targetdefinition-linkline'
11
- require 'cocoapods-bb-PodAssistant/babybus/linkline/targetValidator-linkline'
11
+ require 'cocoapods-bb-PodAssistant/babybus/linkline/targetValidator-linkline'
12
+ # tool
13
+ require 'cocoapods-bb-PodAssistant/tools'
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBbPodassistant
2
- VERSION = "0.3.8.0"
2
+ VERSION = "0.3.10.0"
3
3
  end
@@ -356,8 +356,20 @@ module BB
356
356
  stable_specs.push(data)
357
357
  end
358
358
  elsif pod.is_a? String
359
- # puts "===git===标签==> { names: [\"#{name}\"], version: #{pod}, method: REMOTE_TAG }".green
360
- stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG })
359
+ # 这种情况pod 为版本, 需要从podfile_hash 查询额外信息
360
+ podInfo = podfile_hash.fetch(name, {})
361
+ linkages = podInfo.fetch(:linkages, "") # 如果 :linkages 不存在,返回空字符串
362
+ linkage = podInfo.fetch(:linkage, "") # 同上
363
+ if !linkages.empty?
364
+ # puts "===git===标签==> { podInfo: [\"#{podInfo}\"], linkages: #{linkages} }".green
365
+ stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG, linkages: linkages})
366
+ elsif !linkage.empty?
367
+ # puts "===git===标签==> { podInfo: [\"#{podInfo}\"], linkage: #{linkage} }".green
368
+ stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG, linkage: linkage})
369
+ else
370
+ # puts "===git===标签==> { podInfo: [\"#{podInfo}\"] }".green
371
+ stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG })
372
+ end
361
373
  else
362
374
  puts "unknow type [#{name}] data:#{pod}".red
363
375
  end
@@ -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
@@ -0,0 +1,129 @@
1
+ require 'find'
2
+ module BBItools
3
+ class ClassFinder
4
+ attr_accessor :search_path, :classes, :search_in_files
5
+ def initialize(temp_search_path)
6
+ @search_path = temp_search_path
7
+ @classes = []
8
+ @search_in_files = []
9
+ end
10
+ def search
11
+ # 找到所有的.h以及所有要查找的文件
12
+ Find.find(@search_path) do |path|
13
+ if File.file?(path)
14
+ if !get_not_contain_file_ext.include?(File.extname(path))
15
+ @search_in_files << path
16
+ end
17
+
18
+ if File.extname(path).eql?(".h")
19
+ ff_result = ClassFindResult.new(File.basename(path,".h"),path)
20
+ @classes << ff_result
21
+ end
22
+ end
23
+ end
24
+
25
+ # 删除使用的文件
26
+ use_idxs = Set.new
27
+ @search_in_files.each{|s_file|
28
+ s_containet = ""
29
+ File.read(s_file).each_line do |line|
30
+ s_containet << line
31
+ s_containet << ","
32
+ end
33
+ # 查找所有文件在单个文件中是否被引用
34
+ @classes.each_with_index{|f_result,idx|
35
+ search_file_no_ext = get_no_ext_path(s_file)
36
+ check_file_no_ext = get_no_ext_path(f_result.fr_path)
37
+ # 判断是否是同一个文件或者是通文件的.m/.h,不是同一个文件才查找
38
+ if !check_file_no_ext.eql?(search_file_no_ext)
39
+ inheritance_str = ": #{f_result.fr_name}"
40
+ contain_str = '@"' + f_result.fr_name + '"'
41
+ reference_str = "#{f_result.fr_name}.h"
42
+
43
+ # if s_containet.match(/: #{f_result.fr_name}|@"#{f_result.fr_name}"|#{f_result.fr_name}.h/) != nil
44
+ if s_containet.include?(inheritance_str) or s_containet.include?(contain_str) or s_containet.include?(reference_str)
45
+ use_idxs << f_result
46
+ puts "#{f_result.fr_name}已使用,剩余查找文件数#{@classes.size - use_idxs.size}..."
47
+ end
48
+ end
49
+ }
50
+
51
+ }
52
+ final_result = []
53
+
54
+ temp_final_result_str = ''
55
+ use_idxs.to_a.each {|u_x|
56
+ temp_final_result_str << u_x.fr_name
57
+ temp_final_result_str << ","
58
+ }
59
+ @classes.delete_if {|find_result| temp_final_result_str.include?(find_result.fr_name) }
60
+ puts "\033[32m查找结束,共同无用文件#{@classes.size}个,如下:\033[0m"
61
+ Spreadsheet.client_encoding = 'utf-8'
62
+ book = Spreadsheet::Workbook.new
63
+ sheet1 = book.create_worksheet
64
+ sheet1.row(0)[0] = "序号"
65
+ sheet1.row(0)[1] = "文件名"
66
+ sheet1.row(0)[2] = "文件路径"
67
+ sheet1.row(0)[3] = "文件占用内存大小"
68
+ total_size = 0
69
+ @classes.each_with_index{|r_item,f_index|
70
+ # if !r_item.fr_name.include?("+")
71
+ total_size = total_size + File.size(r_item.fr_path)
72
+ # end
73
+ puts r_item.fr_name
74
+ sheet1.row(f_index+1)[0] = f_index + 1
75
+ sheet1.row(f_index+1)[1] = r_item.fr_name
76
+ sheet1.row(f_index+1)[2] = r_item.fr_path
77
+ sheet1.row(f_index+1).height = 20
78
+ }
79
+ sheet1.column(0).width = 4
80
+ sheet1.column(1).width = 45
81
+ sheet1.column(2).width = 100
82
+ book.write "#{@search_path}/search_unuseclass_result.xls"
83
+ puts "\033[32m文件已经保存到#{@search_path}/search_unuseclass_result.xls,无用文件#{@classes.size}个,预计可减少内存占用#{handleSize(total_size)}\033[0m"
84
+ end
85
+ # 大小格式化
86
+ def handleSize(size)
87
+ if size > 1024 * 1024
88
+ return format("%.2f",(size.to_f/(1024*1024))) + "MB"
89
+ elsif size > 1024
90
+ return format("%.2f",(size.to_f/1024)) + "KB"
91
+ else
92
+ return size.to_s + "B"
93
+ end
94
+ end
95
+ # 不包含后缀的路径
96
+ def get_no_ext_path(item)
97
+ return File.dirname(item) + "/" + File.basename(item,".*")
98
+ end
99
+ # 不需要查找的类
100
+ def get_not_contain_file_ext
101
+ nc_ext = [".jpg",".png",".md",".xls",".xcworkspace",".DS_Store",""]
102
+ return nc_ext
103
+ end
104
+ # 对外暴露
105
+ def self.search_unuse_class(args)
106
+ folder_path = args[0]
107
+ if folder_path.nil?
108
+ puts "\033[31m传入的参数不能为空\033[0m"
109
+ return
110
+ end
111
+ if !File::directory?(folder_path)
112
+ puts "\033[31m参数不是文件夹\033[0m"
113
+ return
114
+ end
115
+ class_finder = ClassFinder.new(folder_path)
116
+ class_finder.search
117
+ end
118
+ end
119
+
120
+ # ------------------------查找结果类------------------------
121
+
122
+ class ClassFindResult
123
+ attr_accessor :fr_name, :fr_path
124
+ def initialize(temp_name,temp_path)
125
+ @fr_name = temp_name
126
+ @fr_path = temp_path
127
+ end
128
+ end
129
+ end