podfileDep 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cocoapods_plugin.rb +5 -1
- data/lib/podfileDep/check/xcodeproj.rb +12 -1
- data/lib/podfileDep/reference/project.rb +48 -2
- data/lib/podfileDep/reference/uninstall.rb +117 -0
- data/lib/podfileDep/reference/unused.rb +13 -2
- data/lib/podfileDep/version.rb +1 -1
- data/lib/podfileDep/yaml/yaml_dep.rb +3 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50e737e2140890e04f3c8d4761e5fe9a95d8744f070fae28c1adb241099f3e9d
|
4
|
+
data.tar.gz: b5e4cb2736576920794a0278fc745c909ec615783fed0eadc0474094d130f1ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad13070d408d863fd0eb1585e7f80323ed284d72af1fdb01b54619c1aab61b7642acf18fc8d48d855e2bb50dbfd8f1f5d52297b4231fddc75440131ed5290fd8
|
7
|
+
data.tar.gz: e9b622927e64d40733416304d3a96c1afca6e7d34735bc7f153a4916b003f43394657066144649a6c10c5ab526ffee59e7c85bbabd9b2763e902342e1c593faf
|
data/lib/cocoapods_plugin.rb
CHANGED
@@ -35,7 +35,11 @@ module CocoapodsPlugin
|
|
35
35
|
Unused::UnusedManager.check_unused
|
36
36
|
|
37
37
|
# 添加yaml到引用和忽略
|
38
|
-
Project::ProjectManager.
|
38
|
+
Project::ProjectManager.yaml_reference
|
39
|
+
|
40
|
+
# 添加yaml到资源文件
|
41
|
+
Project::ProjectManager.yaml_resource
|
42
|
+
|
39
43
|
end
|
40
44
|
|
41
45
|
# Pod::HooksManager.register('podfileDep', :post_integrate) do |context|
|
@@ -75,7 +75,18 @@ module XCProject
|
|
75
75
|
|
76
76
|
end
|
77
77
|
|
78
|
-
#获取主APP target列表
|
78
|
+
#获取主APP target列表 包含扩展
|
79
|
+
def get_shell_targets
|
80
|
+
results = []
|
81
|
+
project = self.get_shell_project
|
82
|
+
targets = project.root_object.targets
|
83
|
+
targets.each do |target|
|
84
|
+
results << target.name
|
85
|
+
end
|
86
|
+
results
|
87
|
+
end
|
88
|
+
|
89
|
+
#获取主APP target列表 不包含扩展
|
79
90
|
def get_app_targets
|
80
91
|
results = []
|
81
92
|
project = self.get_shell_project
|
@@ -1,10 +1,56 @@
|
|
1
1
|
require_relative '../check/xcodeproj'
|
2
2
|
require_relative '../constants'
|
3
|
+
|
3
4
|
module Project
|
4
5
|
class ProjectManager
|
6
|
+
def self.yaml_resource
|
7
|
+
puts "yaml资源文件添加"
|
8
|
+
project_manager = XCProject::XcodeprojManager.share_manager
|
9
|
+
targets = project_manager.get_app_targets
|
10
|
+
targets.each do |target_name|
|
11
|
+
target_supporting = "Pods-#{target_name}"
|
12
|
+
resource_shell = "Pods-#{target_name}-resources.sh"
|
13
|
+
resource_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{resource_shell}"
|
14
|
+
self.yaml_resource_file(resource_shell_path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.yaml_resource_file(file_path)
|
19
|
+
unless File.exist?(file_path)
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
# 读内容
|
24
|
+
content = ""
|
25
|
+
line_array = IO.readlines(file_path)
|
26
|
+
line_array.each_with_index { |line, index|
|
27
|
+
content += line
|
28
|
+
next_line = index<line_array.size ? line_array[index+1] : ""
|
29
|
+
if line.include?("if [[ \"$CONFIGURATION\"") and next_line.include?("install_resource")
|
30
|
+
if File.exist?(Constants::PODFILE_LOCAL_YAML)
|
31
|
+
content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_LOCAL_YAML}\"\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
if File.exist?(Constants::PODFILE_MODULE_YAML)
|
35
|
+
content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_MODULE_YAML}\"\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
if File.exist?(Constants::PODFILE_THIRD_PARTY_YAML)
|
39
|
+
content += " install_resource \"${SRCROOT}/#{Constants::PODFILE_THIRD_PARTY_YAML}\"\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
|
+
|
44
|
+
# 写文件
|
45
|
+
File.open(file_path, 'w') { |file|
|
46
|
+
file.write(content)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
5
50
|
|
6
|
-
|
7
|
-
|
51
|
+
# 将yaml文件加入引用
|
52
|
+
def self.yaml_reference
|
53
|
+
puts "yaml文件引用添加"
|
8
54
|
self.add_yaml
|
9
55
|
self.add_local_yaml_ignore
|
10
56
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative '../check/xcodeproj'
|
2
|
+
module Pod
|
3
|
+
# 移除未使用的组件
|
4
|
+
class Uninstall
|
5
|
+
|
6
|
+
def uninstall(module_name)
|
7
|
+
puts "移除:#{module_name}"
|
8
|
+
project_manager = XCProject::XcodeprojManager.share_manager
|
9
|
+
|
10
|
+
# 删除引用
|
11
|
+
pods_project = project_manager.get_pods_project
|
12
|
+
uninstall_from_project(module_name, pods_project)
|
13
|
+
pods_project.save
|
14
|
+
|
15
|
+
# 删除资源文件等
|
16
|
+
uninstall_from_frameworks(module_name, project_manager)
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def uninstall_from_frameworks(module_name, project_manager)
|
22
|
+
targets = project_manager.get_shell_targets
|
23
|
+
targets.each do |target_name|
|
24
|
+
|
25
|
+
target_supporting = "Pods-#{target_name}"
|
26
|
+
resource_shell = "Pods-#{target_name}-resources.sh"
|
27
|
+
resource_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{resource_shell}"
|
28
|
+
uninstall_from_file(resource_shell_path, module_name, "install_resource")
|
29
|
+
|
30
|
+
# 删除frameworks
|
31
|
+
frameworks_shell = "Pods-#{target_name}-frameworks.sh"
|
32
|
+
frameworks_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{frameworks_shell}"
|
33
|
+
uninstall_from_file(frameworks_shell_path, module_name, "install_framework")
|
34
|
+
|
35
|
+
# 删除配置
|
36
|
+
# 根据通配符找到真实路径
|
37
|
+
config_patton = "Pods-#{target_name}.*.xcconfig"
|
38
|
+
config_patton_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{config_patton}"
|
39
|
+
Dir[config_patton_path].select{|config_real_path|
|
40
|
+
module_name = module_name.gsub("+", "_")
|
41
|
+
module_name = module_name.gsub("-", "_")
|
42
|
+
uninstall_for_config(config_real_path, module_name)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
def uninstall_for_config(file_path, module_name)
|
48
|
+
find_array = []
|
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
|
+
replace = ""
|
56
|
+
replace_str(file_path, find_array, replace)
|
57
|
+
end
|
58
|
+
def uninstall_from_file(file_path, module_name , keyword)
|
59
|
+
unless File.exist?(file_path)
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
# 读内容
|
64
|
+
content = ""
|
65
|
+
line_array = IO.readlines(file_path)
|
66
|
+
line_array.each_with_index { |line, index|
|
67
|
+
if line.include?(keyword) and line.include?("/#{module_name}/")
|
68
|
+
content += " echo 'remove #{module_name}'\n"
|
69
|
+
next
|
70
|
+
end
|
71
|
+
content += line
|
72
|
+
}
|
73
|
+
|
74
|
+
# 写文件
|
75
|
+
File.open(file_path, 'w') { |file|
|
76
|
+
file.write(content)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def uninstall_from_project(module_name, pods_project)
|
81
|
+
pods_project.main_group.children.each {|child|
|
82
|
+
if child.display_name != "Pods" and child.display_name != "Development Pods"
|
83
|
+
next
|
84
|
+
end
|
85
|
+
child.children.reject! {|sun|
|
86
|
+
sun.display_name == module_name
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
pods_project.main_group.children.reject! do |child|
|
91
|
+
(child.class == Array and child.children.size == 0)
|
92
|
+
end
|
93
|
+
|
94
|
+
pods_project.targets.reject! do |child|
|
95
|
+
child.name == module_name
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# 替换文件内的字符串
|
100
|
+
def replace_str(file_path, find_array, replace)
|
101
|
+
unless File.exist?(file_path)
|
102
|
+
return
|
103
|
+
end
|
104
|
+
FileUtils.chmod("+w", file_path)
|
105
|
+
content = File.read(file_path)
|
106
|
+
|
107
|
+
find_array.each do |find|
|
108
|
+
content = content.gsub(find, replace)
|
109
|
+
end
|
110
|
+
|
111
|
+
File.open(file_path, "w") do |file|
|
112
|
+
file.puts content
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require_relative '../check/xcodeproj'
|
2
2
|
require_relative '../podfilelock'
|
3
|
+
require_relative 'uninstall'
|
4
|
+
require_relative '../yaml/yaml_dep'
|
3
5
|
|
4
6
|
module Unused
|
5
7
|
class UnusedManager
|
@@ -24,6 +26,11 @@ module Unused
|
|
24
26
|
return
|
25
27
|
end
|
26
28
|
|
29
|
+
# 是否需要快速编译
|
30
|
+
quick_build = Pod::YamlRelies.quick_build
|
31
|
+
|
32
|
+
uninstaller = Pod::Uninstall.new
|
33
|
+
|
27
34
|
# 未使用的列表
|
28
35
|
unused_list = []
|
29
36
|
installed_modules.each do |module_item|
|
@@ -38,7 +45,11 @@ module Unused
|
|
38
45
|
end
|
39
46
|
|
40
47
|
if not used and not unused_list.include?(real_module_name)
|
41
|
-
|
48
|
+
if quick_build
|
49
|
+
uninstaller.uninstall(real_module_name)
|
50
|
+
else
|
51
|
+
unused_list << real_module_name
|
52
|
+
end
|
42
53
|
end
|
43
54
|
end
|
44
55
|
|
@@ -48,7 +59,7 @@ module Unused
|
|
48
59
|
end
|
49
60
|
|
50
61
|
duration = ((Time.now.to_f * 1000).to_i - start)*0.001
|
51
|
-
puts "
|
62
|
+
puts "未被引用的组件处理完毕! 共检查#{installed_modules.size.to_s}个组件 耗时:#{duration.round(2)}秒"
|
52
63
|
end
|
53
64
|
|
54
65
|
# 获取某个库是否在壳工程内被使用
|
data/lib/podfileDep/version.rb
CHANGED
@@ -364,7 +364,7 @@ module Pod
|
|
364
364
|
return false
|
365
365
|
end
|
366
366
|
|
367
|
-
yaml_content["
|
367
|
+
yaml_content["QUICKBUILD"] == true ? true : false
|
368
368
|
end
|
369
369
|
|
370
370
|
# 生成local文件
|
@@ -379,8 +379,8 @@ module Pod
|
|
379
379
|
content = content + "# 2、PODS下边的配置是数组形式, 如果有多个就写多个\n"
|
380
380
|
content = content + "# 3、本文件加入到忽略文件中\n\n"
|
381
381
|
|
382
|
-
# content = content + "#
|
383
|
-
# content = content + "
|
382
|
+
# content = content + "# QUICKBUILD字段如果为true, 则表示会自动解析所有组件的依赖, 并删除不被使用的依赖库, 以达到开发时快速编译的目的\n"
|
383
|
+
# content = content + "QUICKBUILD: false\n\n"
|
384
384
|
|
385
385
|
content = content + "PODS:\n"
|
386
386
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: podfileDep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 王帅朋
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/podfileDep/modify/modify_code.rb
|
64
64
|
- lib/podfileDep/podfilelock.rb
|
65
65
|
- lib/podfileDep/reference/project.rb
|
66
|
+
- lib/podfileDep/reference/uninstall.rb
|
66
67
|
- lib/podfileDep/reference/unused.rb
|
67
68
|
- lib/podfileDep/version.rb
|
68
69
|
- lib/podfileDep/yaml/yaml_dep.rb
|