podfileDep 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/podfileDep/reference/uninstall.rb +36 -24
- data/lib/podfileDep/reference/unused.rb +13 -5
- data/lib/podfileDep/version.rb +1 -1
- data/lib/podfileDep/yaml/yaml_dep.rb +46 -23
- data/lib/podfileDep.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d685c50ac91b5bc9100a895fe300df13c8d1f4ca29eec6cfd0d36c1e74edaf08
|
4
|
+
data.tar.gz: 60365a5983ce3810316f3b72b061e38717dfbd1f4ae34838f395a90659c4f755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3dc46f47e0a2f3fdff945c663396ae3f1727dd2a62f5c6e2c939be6d528f2045469c9bb73d75d6b27be317ec9aee34a1e6e7fe9509875d868df603579a9327d
|
7
|
+
data.tar.gz: b0bcbd47cf7ecad5c0f19a597fb531708b2b31f4da06b2bdc885985901dac4b0276bb4f3ca85f5810f404feb7ff786ec2bdd2ac402f850ee48221e14b0aae1f1
|
data/CHANGELOG.md
CHANGED
@@ -3,59 +3,61 @@ module Pod
|
|
3
3
|
# 移除未使用的组件
|
4
4
|
class Uninstall
|
5
5
|
|
6
|
-
def uninstall(
|
7
|
-
puts "移除:#{module_name}"
|
6
|
+
def uninstall(uninstall_list)
|
8
7
|
project_manager = XCProject::XcodeprojManager.share_manager
|
9
8
|
|
10
9
|
# 删除引用
|
11
10
|
pods_project = project_manager.get_pods_project
|
12
|
-
uninstall_from_project(
|
11
|
+
uninstall_from_project(uninstall_list, pods_project)
|
13
12
|
pods_project.save
|
14
13
|
|
15
14
|
# 删除资源文件等
|
16
|
-
uninstall_from_frameworks(
|
17
|
-
|
15
|
+
uninstall_from_frameworks(uninstall_list, project_manager)
|
18
16
|
|
19
17
|
end
|
20
18
|
|
21
|
-
def uninstall_from_frameworks(
|
19
|
+
def uninstall_from_frameworks(module_list, project_manager)
|
22
20
|
targets = project_manager.get_shell_targets
|
23
21
|
targets.each do |target_name|
|
24
22
|
|
25
23
|
target_supporting = "Pods-#{target_name}"
|
26
24
|
resource_shell = "Pods-#{target_name}-resources.sh"
|
27
25
|
resource_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{resource_shell}"
|
28
|
-
uninstall_from_file(resource_shell_path,
|
26
|
+
uninstall_from_file(resource_shell_path, module_list, "install_resource")
|
29
27
|
|
30
28
|
# 删除frameworks
|
31
29
|
frameworks_shell = "Pods-#{target_name}-frameworks.sh"
|
32
30
|
frameworks_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{frameworks_shell}"
|
33
|
-
uninstall_from_file(frameworks_shell_path,
|
31
|
+
uninstall_from_file(frameworks_shell_path, module_list, "install_framework")
|
34
32
|
|
35
33
|
# 删除配置
|
36
34
|
# 根据通配符找到真实路径
|
37
35
|
config_patton = "Pods-#{target_name}.*.xcconfig"
|
38
36
|
config_patton_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{config_patton}"
|
39
37
|
Dir[config_patton_path].select{|config_real_path|
|
40
|
-
|
41
|
-
module_name = module_name.gsub("-", "_")
|
42
|
-
uninstall_for_config(config_real_path, module_name)
|
38
|
+
uninstall_for_config(config_real_path, module_list)
|
43
39
|
}
|
44
40
|
end
|
45
41
|
|
46
42
|
end
|
47
|
-
def uninstall_for_config(file_path,
|
43
|
+
def uninstall_for_config(file_path, module_list)
|
48
44
|
find_array = []
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
module_list.each do |module_name|
|
46
|
+
module_name = module_name.gsub("+", "_")
|
47
|
+
module_name = module_name.gsub("-", "_")
|
48
|
+
|
49
|
+
find_array << " -framework \"#{module_name}\""
|
50
|
+
find_array << " \"${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}/#{module_name}.framework/Headers\""
|
51
|
+
find_array << " \"${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}\""
|
52
|
+
find_array << " \"${PODS_ROOT}/#{module_name}\""
|
53
|
+
find_array << " \"${PODS_XCFRAMEWORKS_BUILD_DIR}/#{module_name}\""
|
54
|
+
|
55
|
+
end
|
54
56
|
|
55
57
|
replace = ""
|
56
58
|
replace_str(file_path, find_array, replace)
|
57
59
|
end
|
58
|
-
def uninstall_from_file(file_path,
|
60
|
+
def uninstall_from_file(file_path, module_list , keyword)
|
59
61
|
unless File.exist?(file_path)
|
60
62
|
return
|
61
63
|
end
|
@@ -64,9 +66,19 @@ module Pod
|
|
64
66
|
content = ""
|
65
67
|
line_array = IO.readlines(file_path)
|
66
68
|
line_array.each_with_index { |line, index|
|
67
|
-
if line.include?(keyword)
|
68
|
-
|
69
|
-
|
69
|
+
if line.include?(keyword)
|
70
|
+
contain = false
|
71
|
+
module_list.each{|module_name|
|
72
|
+
if line.include?("/#{module_name}/")
|
73
|
+
contain = true
|
74
|
+
end
|
75
|
+
}
|
76
|
+
|
77
|
+
if contain
|
78
|
+
content += " echo ''\n"
|
79
|
+
next
|
80
|
+
end
|
81
|
+
|
70
82
|
end
|
71
83
|
content += line
|
72
84
|
}
|
@@ -77,13 +89,13 @@ module Pod
|
|
77
89
|
}
|
78
90
|
end
|
79
91
|
|
80
|
-
def uninstall_from_project(
|
92
|
+
def uninstall_from_project(module_list, pods_project)
|
81
93
|
pods_project.main_group.children.each {|child|
|
82
94
|
if child.display_name != "Pods" and child.display_name != "Development Pods"
|
83
95
|
next
|
84
96
|
end
|
85
97
|
child.children.reject! {|sun|
|
86
|
-
sun.display_name
|
98
|
+
module_list.include?(sun.display_name)
|
87
99
|
}
|
88
100
|
}
|
89
101
|
|
@@ -92,7 +104,7 @@ module Pod
|
|
92
104
|
end
|
93
105
|
|
94
106
|
pods_project.targets.reject! do |child|
|
95
|
-
child.
|
107
|
+
module_list.include?(child.display_name)
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
@@ -27,12 +27,13 @@ module Unused
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# 是否需要快速编译
|
30
|
-
quick_build = Pod::
|
30
|
+
quick_build = Pod::YamlManager.share_manager.quick_build
|
31
31
|
|
32
32
|
uninstaller = Pod::Uninstall.new
|
33
33
|
|
34
34
|
# 未使用的列表
|
35
35
|
unused_list = []
|
36
|
+
uninstall_list = []
|
36
37
|
installed_modules.each do |module_item|
|
37
38
|
|
38
39
|
module_name = module_item.keys[0]
|
@@ -45,8 +46,9 @@ module Unused
|
|
45
46
|
end
|
46
47
|
|
47
48
|
if not used and not unused_list.include?(real_module_name)
|
48
|
-
|
49
|
-
|
49
|
+
local_contain = Pod::YamlManager.share_manager.local_yaml_contain(real_module_name)
|
50
|
+
if quick_build and not local_contain
|
51
|
+
uninstall_list << real_module_name
|
50
52
|
else
|
51
53
|
unused_list << real_module_name
|
52
54
|
end
|
@@ -54,8 +56,14 @@ module Unused
|
|
54
56
|
end
|
55
57
|
|
56
58
|
if unused_list.size >0
|
57
|
-
puts unused_list
|
58
|
-
puts "
|
59
|
+
# puts unused_list
|
60
|
+
puts "未被任何地方引用的组件:#{unused_list}"
|
61
|
+
end
|
62
|
+
|
63
|
+
if uninstall_list.size > 0
|
64
|
+
# puts uninstall_list
|
65
|
+
puts "被移除组件:#{uninstall_list}"
|
66
|
+
uninstaller.uninstall(uninstall_list)
|
59
67
|
end
|
60
68
|
|
61
69
|
duration = ((Time.now.to_f * 1000).to_i - start)*0.001
|
data/lib/podfileDep/version.rb
CHANGED
@@ -42,9 +42,27 @@ module Pod
|
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
45
|
-
class
|
45
|
+
class YamlManager
|
46
46
|
|
47
|
-
|
47
|
+
# 缓存某个的依赖库
|
48
|
+
# {{"module_nameA":["module_nameA", module_nameB]},}
|
49
|
+
attr_accessor :local_yaml_dependencies
|
50
|
+
|
51
|
+
def initialize
|
52
|
+
@local_yaml_dependencies = {}
|
53
|
+
end
|
54
|
+
|
55
|
+
# 单例方法
|
56
|
+
@@instance = YamlManager.new
|
57
|
+
|
58
|
+
# 获取单例
|
59
|
+
def self.share_manager
|
60
|
+
@@instance
|
61
|
+
end
|
62
|
+
|
63
|
+
private_class_method :new
|
64
|
+
|
65
|
+
def analysis_yaml(podfile, old)
|
48
66
|
|
49
67
|
# 获取targets列表
|
50
68
|
project_manager = XCProject::XcodeprojManager.share_manager
|
@@ -56,25 +74,26 @@ module Pod
|
|
56
74
|
podfile_third_party_yaml = Constants::PODFILE_THIRD_PARTY_YAML
|
57
75
|
|
58
76
|
# 检查参数
|
59
|
-
|
77
|
+
check_param(targets)
|
60
78
|
|
61
79
|
# 生成YAML文件
|
62
|
-
|
63
|
-
|
64
|
-
|
80
|
+
generate_local_yaml(podfile_local_yaml)
|
81
|
+
generate_module_yaml(podfile_module_yaml, "# 企业内部组件")
|
82
|
+
generate_module_yaml(podfile_third_party_yaml, "# 第三方维护组件")
|
65
83
|
|
66
84
|
# 读取yaml依赖
|
67
85
|
yaml_dependencies = {}
|
68
|
-
|
69
|
-
|
70
|
-
|
86
|
+
read_yaml_dependencies(podfile_third_party_yaml,false ,yaml_dependencies)
|
87
|
+
local_yaml_dependencies = yaml_dependencies #这里记录下
|
88
|
+
read_yaml_dependencies(podfile_module_yaml,false ,yaml_dependencies)
|
89
|
+
read_yaml_dependencies(podfile_local_yaml,true ,yaml_dependencies)
|
71
90
|
|
72
91
|
# 打印依赖
|
73
|
-
|
92
|
+
print_dependencies(yaml_dependencies)
|
74
93
|
|
75
94
|
# 为所有target生成依赖
|
76
95
|
targets_dependencies = {}
|
77
|
-
|
96
|
+
update_target_dependencies(targets, yaml_dependencies, targets_dependencies)
|
78
97
|
|
79
98
|
# 兼容老方式
|
80
99
|
if old
|
@@ -82,11 +101,11 @@ module Pod
|
|
82
101
|
end
|
83
102
|
|
84
103
|
# 存储所有依赖
|
85
|
-
|
104
|
+
store_dependencies(targets_dependencies, podfile)
|
86
105
|
|
87
106
|
end
|
88
107
|
|
89
|
-
def
|
108
|
+
def store_dependencies(targets, podfile)
|
90
109
|
# 存储所有的依赖
|
91
110
|
targets.each { |name, dependencies|
|
92
111
|
podfile.target name do
|
@@ -104,7 +123,7 @@ module Pod
|
|
104
123
|
end
|
105
124
|
|
106
125
|
# 检查方法调用的参数
|
107
|
-
def
|
126
|
+
def check_param(targets)
|
108
127
|
msg = "❌ 参数需要填写target名字, 参数类型是字符串格式的数组。例如[\"test1\", \"test2\"]"
|
109
128
|
unless targets.class == Array
|
110
129
|
puts msg
|
@@ -120,7 +139,7 @@ module Pod
|
|
120
139
|
end
|
121
140
|
|
122
141
|
# 校验yaml文件写法是否正确
|
123
|
-
def
|
142
|
+
def yaml_content(yaml_name)
|
124
143
|
unless File.exist?(yaml_name)
|
125
144
|
puts "文件不存在:"+yaml_name
|
126
145
|
return nil
|
@@ -166,10 +185,10 @@ module Pod
|
|
166
185
|
end
|
167
186
|
|
168
187
|
# 读取yaml依赖
|
169
|
-
def
|
188
|
+
def read_yaml_dependencies(yaml_name, can_cover, yaml_dependencies)
|
170
189
|
|
171
190
|
# 检查写法
|
172
|
-
yaml_content =
|
191
|
+
yaml_content = yaml_content(yaml_name)
|
173
192
|
|
174
193
|
unless yaml_content
|
175
194
|
return
|
@@ -202,7 +221,7 @@ module Pod
|
|
202
221
|
dependency.each_key { |key|
|
203
222
|
unless available_keys.include?(key)
|
204
223
|
gem_name = "yaml_relies"
|
205
|
-
puts "❌ #{yaml_name}: 当前#{gem_name}版本(#{
|
224
|
+
puts "❌ #{yaml_name}: 当前#{gem_name}版本(#{PodfileDep::VERSION})不支持字段#{key}"
|
206
225
|
puts "请检查对应字段或尝试执行如下命令升级"
|
207
226
|
puts "gem uninstall #{gem_name} && gem install #{gem_name}"
|
208
227
|
exit!
|
@@ -297,7 +316,7 @@ module Pod
|
|
297
316
|
end
|
298
317
|
|
299
318
|
# 生成传进来的target的依赖库列表
|
300
|
-
def
|
319
|
+
def update_target_dependencies(targets, yaml_dependencies, targets_dependencies)
|
301
320
|
temp_array = []
|
302
321
|
yaml_dependencies.each_value { |value|
|
303
322
|
temp_array << value
|
@@ -308,7 +327,7 @@ module Pod
|
|
308
327
|
}
|
309
328
|
end
|
310
329
|
|
311
|
-
def
|
330
|
+
def print_dependencies(yaml_dependencies)
|
312
331
|
puts "➡️ 解析依赖总数共计:#{yaml_dependencies.size}个\n\n"
|
313
332
|
puts '⬇️ 打印依赖'
|
314
333
|
yaml_dependencies.each_value { |dependency|
|
@@ -347,8 +366,12 @@ module Pod
|
|
347
366
|
puts "⬆️ 打印完毕"
|
348
367
|
end
|
349
368
|
|
369
|
+
def local_yaml_contain(module_name)
|
370
|
+
return local_yaml_dependencies.keys.include?(module_name)
|
371
|
+
end
|
372
|
+
|
350
373
|
# 是否需要快速编译
|
351
|
-
def
|
374
|
+
def quick_build
|
352
375
|
|
353
376
|
podfile_local_yaml = Constants::PODFILE_LOCAL_YAML
|
354
377
|
|
@@ -368,7 +391,7 @@ module Pod
|
|
368
391
|
end
|
369
392
|
|
370
393
|
# 生成local文件
|
371
|
-
def
|
394
|
+
def generate_local_yaml(podfile_local_yaml)
|
372
395
|
if File.exist?(podfile_local_yaml)
|
373
396
|
return
|
374
397
|
end
|
@@ -404,7 +427,7 @@ module Pod
|
|
404
427
|
end
|
405
428
|
|
406
429
|
# 生成其他的yaml文件
|
407
|
-
def
|
430
|
+
def generate_module_yaml(yaml_name, prefix)
|
408
431
|
if File.exist?(yaml_name)
|
409
432
|
return
|
410
433
|
end
|
data/lib/podfileDep.rb
CHANGED
@@ -9,7 +9,7 @@ module Pod
|
|
9
9
|
plugin("podfileDep")
|
10
10
|
|
11
11
|
# 解析依赖
|
12
|
-
Pod::
|
12
|
+
Pod::YamlManager.share_manager.analysis_yaml(self, false)
|
13
13
|
|
14
14
|
end
|
15
15
|
end
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
# 兼容旧的方式
|
19
19
|
module PodfileDep
|
20
20
|
def PodfileDep.setup(targets)
|
21
|
-
res = Pod::
|
21
|
+
res = Pod::YamlManager.share_manager.analysis_yaml(nil, true)
|
22
22
|
warn "\n⚠️ [PodfileDep.setup方法已过期],请使用新的方式, 参考:https://gitee.com/sourceiOS/podfileDepDemo/blob/master/Podfile\n"
|
23
23
|
res
|
24
24
|
end
|