podfileDep 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,129 +0,0 @@
1
- require_relative '../check/xcodeproj'
2
- module Pod
3
- # 移除未使用的组件
4
- class Uninstall
5
-
6
- def uninstall(uninstall_list)
7
- project_manager = XCProject::XcodeprojManager.share_manager
8
-
9
- # 删除引用
10
- pods_project = project_manager.get_pods_project
11
- uninstall_from_project(uninstall_list, pods_project)
12
- pods_project.save
13
-
14
- # 删除资源文件等
15
- uninstall_from_frameworks(uninstall_list, project_manager)
16
-
17
- end
18
-
19
- def uninstall_from_frameworks(module_list, project_manager)
20
- targets = project_manager.get_shell_targets
21
- targets.each do |target_name|
22
-
23
- target_supporting = "Pods-#{target_name}"
24
- resource_shell = "Pods-#{target_name}-resources.sh"
25
- resource_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{resource_shell}"
26
- uninstall_from_file(resource_shell_path, module_list, "install_resource")
27
-
28
- # 删除frameworks
29
- frameworks_shell = "Pods-#{target_name}-frameworks.sh"
30
- frameworks_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{frameworks_shell}"
31
- uninstall_from_file(frameworks_shell_path, module_list, "install_framework")
32
-
33
- # 删除配置
34
- # 根据通配符找到真实路径
35
- config_patton = "Pods-#{target_name}.*.xcconfig"
36
- config_patton_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{config_patton}"
37
- Dir[config_patton_path].select{|config_real_path|
38
- uninstall_for_config(config_real_path, module_list)
39
- }
40
- end
41
-
42
- end
43
- def uninstall_for_config(file_path, module_list)
44
- find_array = []
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
56
-
57
- replace = ""
58
- replace_str(file_path, find_array, replace)
59
- end
60
- def uninstall_from_file(file_path, module_list , keyword)
61
- unless File.exist?(file_path)
62
- return
63
- end
64
-
65
- # 读内容
66
- content = ""
67
- line_array = IO.readlines(file_path)
68
- line_array.each_with_index { |line, index|
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
-
82
- end
83
- content += line
84
- }
85
-
86
- # 写文件
87
- File.open(file_path, 'w') { |file|
88
- file.write(content)
89
- }
90
- end
91
-
92
- def uninstall_from_project(module_list, pods_project)
93
- pods_project.main_group.children.each {|child|
94
- if child.display_name != "Pods" and child.display_name != "Development Pods"
95
- next
96
- end
97
- child.children.reject! {|sun|
98
- module_list.include?(sun.display_name)
99
- }
100
- }
101
-
102
- pods_project.main_group.children.reject! do |child|
103
- (child.class == Array and child.children.size == 0)
104
- end
105
-
106
- pods_project.targets.reject! do |child|
107
- module_list.include?(child.display_name)
108
- end
109
- end
110
-
111
- # 替换文件内的字符串
112
- def replace_str(file_path, find_array, replace)
113
- unless File.exist?(file_path)
114
- return
115
- end
116
- FileUtils.chmod("+w", file_path)
117
- content = File.read(file_path)
118
-
119
- find_array.each do |find|
120
- content = content.gsub(find, replace)
121
- end
122
-
123
- File.open(file_path, "w") do |file|
124
- file.puts content
125
- end
126
- end
127
-
128
- end
129
- end