podfileDep 2.1.0 → 2.1.2
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 +4 -4
- data/CHANGELOG.md +13 -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 +48 -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: 98e0473afab8ed38d19dd5fe2f1483ba2d8bb592d364b9c29bceda3314c65d46
|
4
|
+
data.tar.gz: 37f8f5306318c471f98052415912563c397515f573aa4cde506343959bc0ee57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27250cce3354cc8af046c4a3c410ad6ef9e9b181973d8a6a00ed780af64871a710df85231e6ec1f3fafbbfc7c75663a67a55e890ed28cca25244aad4172775ed
|
7
|
+
data.tar.gz: 6cc16f12cd5690f8508f6b4949e6c45d272d7965a69927fcabda0dc65fa75a542d5a3504a2d395f38a88737c8860f8fb97291e34d1f7b4ab9144f8e9d9d42ec7
|
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,25 @@ module Pod
|
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
45
|
-
class
|
45
|
+
class YamlManager
|
46
46
|
|
47
|
-
|
47
|
+
attr_accessor :local_yaml_deps
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
@local_yaml_deps = []
|
51
|
+
end
|
52
|
+
|
53
|
+
# 单例方法
|
54
|
+
@@instance = YamlManager.new
|
55
|
+
|
56
|
+
# 获取单例
|
57
|
+
def self.share_manager
|
58
|
+
@@instance
|
59
|
+
end
|
60
|
+
|
61
|
+
private_class_method :new
|
62
|
+
|
63
|
+
def analysis_yaml(podfile, old)
|
48
64
|
|
49
65
|
# 获取targets列表
|
50
66
|
project_manager = XCProject::XcodeprojManager.share_manager
|
@@ -56,25 +72,25 @@ module Pod
|
|
56
72
|
podfile_third_party_yaml = Constants::PODFILE_THIRD_PARTY_YAML
|
57
73
|
|
58
74
|
# 检查参数
|
59
|
-
|
75
|
+
check_param(targets)
|
60
76
|
|
61
77
|
# 生成YAML文件
|
62
|
-
|
63
|
-
|
64
|
-
|
78
|
+
generate_local_yaml(podfile_local_yaml)
|
79
|
+
generate_module_yaml(podfile_module_yaml, "# 企业内部组件")
|
80
|
+
generate_module_yaml(podfile_third_party_yaml, "# 第三方维护组件")
|
65
81
|
|
66
82
|
# 读取yaml依赖
|
67
83
|
yaml_dependencies = {}
|
68
|
-
|
69
|
-
|
70
|
-
|
84
|
+
read_yaml_dependencies(podfile_third_party_yaml,false ,yaml_dependencies)
|
85
|
+
read_yaml_dependencies(podfile_module_yaml,false ,yaml_dependencies)
|
86
|
+
read_yaml_dependencies(podfile_local_yaml,true ,yaml_dependencies)
|
71
87
|
|
72
88
|
# 打印依赖
|
73
|
-
|
89
|
+
print_dependencies(yaml_dependencies)
|
74
90
|
|
75
91
|
# 为所有target生成依赖
|
76
92
|
targets_dependencies = {}
|
77
|
-
|
93
|
+
update_target_dependencies(targets, yaml_dependencies, targets_dependencies)
|
78
94
|
|
79
95
|
# 兼容老方式
|
80
96
|
if old
|
@@ -82,11 +98,11 @@ module Pod
|
|
82
98
|
end
|
83
99
|
|
84
100
|
# 存储所有依赖
|
85
|
-
|
101
|
+
store_dependencies(targets_dependencies, podfile)
|
86
102
|
|
87
103
|
end
|
88
104
|
|
89
|
-
def
|
105
|
+
def store_dependencies(targets, podfile)
|
90
106
|
# 存储所有的依赖
|
91
107
|
targets.each { |name, dependencies|
|
92
108
|
podfile.target name do
|
@@ -104,7 +120,7 @@ module Pod
|
|
104
120
|
end
|
105
121
|
|
106
122
|
# 检查方法调用的参数
|
107
|
-
def
|
123
|
+
def check_param(targets)
|
108
124
|
msg = "❌ 参数需要填写target名字, 参数类型是字符串格式的数组。例如[\"test1\", \"test2\"]"
|
109
125
|
unless targets.class == Array
|
110
126
|
puts msg
|
@@ -120,7 +136,7 @@ module Pod
|
|
120
136
|
end
|
121
137
|
|
122
138
|
# 校验yaml文件写法是否正确
|
123
|
-
def
|
139
|
+
def yaml_content(yaml_name)
|
124
140
|
unless File.exist?(yaml_name)
|
125
141
|
puts "文件不存在:"+yaml_name
|
126
142
|
return nil
|
@@ -166,10 +182,10 @@ module Pod
|
|
166
182
|
end
|
167
183
|
|
168
184
|
# 读取yaml依赖
|
169
|
-
def
|
185
|
+
def read_yaml_dependencies(yaml_name, can_cover, yaml_dependencies)
|
170
186
|
|
171
187
|
# 检查写法
|
172
|
-
yaml_content =
|
188
|
+
yaml_content = yaml_content(yaml_name)
|
173
189
|
|
174
190
|
unless yaml_content
|
175
191
|
return
|
@@ -202,7 +218,7 @@ module Pod
|
|
202
218
|
dependency.each_key { |key|
|
203
219
|
unless available_keys.include?(key)
|
204
220
|
gem_name = "yaml_relies"
|
205
|
-
puts "❌ #{yaml_name}: 当前#{gem_name}版本(#{
|
221
|
+
puts "❌ #{yaml_name}: 当前#{gem_name}版本(#{PodfileDep::VERSION})不支持字段#{key}"
|
206
222
|
puts "请检查对应字段或尝试执行如下命令升级"
|
207
223
|
puts "gem uninstall #{gem_name} && gem install #{gem_name}"
|
208
224
|
exit!
|
@@ -277,6 +293,11 @@ module Pod
|
|
277
293
|
binary = dependency['binary'] ? !!dependency['binary'] : true
|
278
294
|
version = (dependency['path'] or dependency['podspec']) ? nil :dependency['version']
|
279
295
|
|
296
|
+
# 记录
|
297
|
+
if yaml_name == Constants::PODFILE_LOCAL_YAML
|
298
|
+
self.local_yaml_deps << dependency['pod']
|
299
|
+
end
|
300
|
+
|
280
301
|
# 生成依赖对象
|
281
302
|
dependency = YamlRely.new(module_name = dependency['module'],
|
282
303
|
pod = dependency['pod'],
|
@@ -297,7 +318,7 @@ module Pod
|
|
297
318
|
end
|
298
319
|
|
299
320
|
# 生成传进来的target的依赖库列表
|
300
|
-
def
|
321
|
+
def update_target_dependencies(targets, yaml_dependencies, targets_dependencies)
|
301
322
|
temp_array = []
|
302
323
|
yaml_dependencies.each_value { |value|
|
303
324
|
temp_array << value
|
@@ -308,7 +329,7 @@ module Pod
|
|
308
329
|
}
|
309
330
|
end
|
310
331
|
|
311
|
-
def
|
332
|
+
def print_dependencies(yaml_dependencies)
|
312
333
|
puts "➡️ 解析依赖总数共计:#{yaml_dependencies.size}个\n\n"
|
313
334
|
puts '⬇️ 打印依赖'
|
314
335
|
yaml_dependencies.each_value { |dependency|
|
@@ -347,8 +368,12 @@ module Pod
|
|
347
368
|
puts "⬆️ 打印完毕"
|
348
369
|
end
|
349
370
|
|
371
|
+
def local_yaml_contain(module_name)
|
372
|
+
local_yaml_deps.include?(module_name)
|
373
|
+
end
|
374
|
+
|
350
375
|
# 是否需要快速编译
|
351
|
-
def
|
376
|
+
def quick_build
|
352
377
|
|
353
378
|
podfile_local_yaml = Constants::PODFILE_LOCAL_YAML
|
354
379
|
|
@@ -368,7 +393,7 @@ module Pod
|
|
368
393
|
end
|
369
394
|
|
370
395
|
# 生成local文件
|
371
|
-
def
|
396
|
+
def generate_local_yaml(podfile_local_yaml)
|
372
397
|
if File.exist?(podfile_local_yaml)
|
373
398
|
return
|
374
399
|
end
|
@@ -404,7 +429,7 @@ module Pod
|
|
404
429
|
end
|
405
430
|
|
406
431
|
# 生成其他的yaml文件
|
407
|
-
def
|
432
|
+
def generate_module_yaml(yaml_name, prefix)
|
408
433
|
if File.exist?(yaml_name)
|
409
434
|
return
|
410
435
|
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
|