podfileDep 2.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 453cf499c1ff0edb3b114d9557593fe4ec231f32e06b4184be2023004af7266a
4
- data.tar.gz: 036b6aa3bd30e6f504d9819c671295fdf454f1f8d6b35b04dac997094e9664b8
3
+ metadata.gz: 50e737e2140890e04f3c8d4761e5fe9a95d8744f070fae28c1adb241099f3e9d
4
+ data.tar.gz: b5e4cb2736576920794a0278fc745c909ec615783fed0eadc0474094d130f1ca
5
5
  SHA512:
6
- metadata.gz: 47482290d3a12ddae5d48a5251cbd29ee5e26887174f432e122f9785007769794fa53a9fb9bae498cf214eeb17c44b830dd3c9104cc5bea440ab60706083fb1d
7
- data.tar.gz: 995f1fea91965ea4252d9611a2f8ea7d35eb90d0d76bd02a40d4e81953be2ceff900ce24505ea56c76e8f66fef031b8dbcda7875e5d78c1ecd3000ffb1f36e11
6
+ metadata.gz: ad13070d408d863fd0eb1585e7f80323ed284d72af1fdb01b54619c1aab61b7642acf18fc8d48d855e2bb50dbfd8f1f5d52297b4231fddc75440131ed5290fd8
7
+ data.tar.gz: e9b622927e64d40733416304d3a96c1afca6e7d34735bc7f153a4916b003f43394657066144649a6c10c5ab526ffee59e7c85bbabd9b2763e902342e1c593faf
data/CHANGELOG.md CHANGED
@@ -28,4 +28,8 @@
28
28
 
29
29
  - 全新使用方式接入,更加方便,仅需一行代码接入
30
30
  - yaml文件新增字段检验,支持subspecs字段
31
- - 对文件中import的检验更加准确
31
+ - 对文件中import的检验更加准确
32
+
33
+ ## [2.0.1] - 2023-6-19
34
+
35
+ - 打印间接依赖
@@ -4,15 +4,16 @@ require_relative 'podfileDep/check/import'
4
4
  require_relative 'podfileDep/modify/modify_code'
5
5
  require_relative 'podfileDep/reference/unused'
6
6
  require_relative 'podfileDep/reference/project'
7
+ require_relative 'podfileDep/indirect/indirect'
7
8
 
8
9
  # 注册插件
9
10
  module CocoapodsPlugin
10
- # Pod::HooksManager.register('yaml_relies', :source_provider) do |context|
11
+ # Pod::HooksManager.register('podfileDep', :source_provider) do |context|
11
12
  # puts "hook source_provider"
12
13
  # puts context
13
14
  # end
14
15
  #
15
- # Pod::HooksManager.register('yaml_relies', :pre_install) do |context|
16
+ # Pod::HooksManager.register('podfileDep', :pre_install) do |context|
16
17
  # puts "hook pre_install"
17
18
  # puts context
18
19
  # end
@@ -27,14 +28,21 @@ module CocoapodsPlugin
27
28
  # 代码文件处理
28
29
  ModifyCode::Modify.modify_fb
29
30
 
31
+ # 间接依赖
32
+ PodfileLock::Indirect.new.log_indirect
33
+
30
34
  # 未被使用的依赖库
31
35
  Unused::UnusedManager.check_unused
32
36
 
33
37
  # 添加yaml到引用和忽略
34
- Project::ProjectManager.yaml_deal
38
+ Project::ProjectManager.yaml_reference
39
+
40
+ # 添加yaml到资源文件
41
+ Project::ProjectManager.yaml_resource
42
+
35
43
  end
36
44
 
37
- # Pod::HooksManager.register('yaml_relies', :post_integrate) do |context|
45
+ # Pod::HooksManager.register('podfileDep', :post_integrate) do |context|
38
46
  # puts context
39
47
  # end
40
48
  end
@@ -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
@@ -0,0 +1,37 @@
1
+ require_relative '../podfilelock'
2
+
3
+ module PodfileLock
4
+ class Indirect
5
+ def log_indirect
6
+
7
+ # 内容读取
8
+ dependencies_lock = PodfileLock::PodfileLockManager.podfile_lock_content
9
+
10
+ dependencies = dependencies_lock['DEPENDENCIES']
11
+ unless dependencies
12
+ return
13
+ end
14
+
15
+ check_sums = dependencies_lock['SPEC CHECKSUMS']
16
+ unless check_sums
17
+ return
18
+ end
19
+
20
+ # 数组处理
21
+ check_values = dependencies.collect! {|item|
22
+ item.split(' (')[0]
23
+ }
24
+ check_values = dependencies.collect! {|item|
25
+ item.split('/')[0]
26
+ }
27
+
28
+ puts ''
29
+ check_sums.each{ |array|
30
+ be_check_value = array[0]
31
+ unless check_values.include?(be_check_value)
32
+ puts '↪️ 间接依赖: '+ be_check_value
33
+ end
34
+ }
35
+ end
36
+ end
37
+ end
@@ -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
- def self.yaml_deal
7
- puts "yaml文件处理"
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
- unused_list << real_module_name
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 "未被引用的组件检查完毕! 共检查#{installed_modules.size.to_s}个组件 耗时:#{duration.round(2)}秒"
62
+ puts "未被引用的组件处理完毕! 共检查#{installed_modules.size.to_s}个组件 耗时:#{duration.round(2)}秒"
52
63
  end
53
64
 
54
65
  # 获取某个库是否在壳工程内被使用
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PodfileDep
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -364,7 +364,7 @@ module Pod
364
364
  return false
365
365
  end
366
366
 
367
- yaml_content["QUICK"] == true ? true : false
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 + "# QUICK字段如果为true, 则表示会自动解析所有组件的依赖, 并删除不被使用的依赖库, 以达到开发时快速编译的目的\n"
383
- # content = content + "QUICK: false\n\n"
382
+ # content = content + "# QUICKBUILD字段如果为true, 则表示会自动解析所有组件的依赖, 并删除不被使用的依赖库, 以达到开发时快速编译的目的\n"
383
+ # content = content + "QUICKBUILD: false\n\n"
384
384
 
385
385
  content = content + "PODS:\n"
386
386
 
data/lib/podfileDep.rb CHANGED
@@ -18,8 +18,9 @@ end
18
18
  # 兼容旧的方式
19
19
  module PodfileDep
20
20
  def PodfileDep.setup(targets)
21
- warn "[PodfileDep.setup方法已过期],请使用新的方式, 参考:https://gitee.com/sourceiOS/podfileDepDemo/blob/master/Podfile"
22
- Pod::YamlRelies.analysis_yaml(nil, true)
21
+ res = Pod::YamlRelies.analysis_yaml(nil, true)
22
+ warn "\n⚠️ [PodfileDep.setup方法已过期],请使用新的方式, 参考:https://gitee.com/sourceiOS/podfileDepDemo/blob/master/Podfile\n"
23
+ res
23
24
  end
24
25
 
25
26
  end
data/podfileDep.gemspec CHANGED
@@ -5,12 +5,12 @@ require_relative "lib/podfileDep/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "podfileDep"
7
7
  spec.version = PodfileDep::VERSION
8
- spec.authors = ["WANGSHUAIPENG"]
8
+ spec.authors = ["王帅朋"]
9
9
  spec.email = ["wsp810@163.com"]
10
10
 
11
- spec.summary = " podfile依赖管理."
12
- spec.description = "iOS 端Podfile文件托管"
13
- spec.homepage = "https://gitee.com/sourceiOS/podfileDep"
11
+ spec.summary = "iOS端 依赖库使用yaml文件管理"
12
+ spec.description = "iOS 依赖库使用yaml文件管理,并提供其他扩展功能"
13
+ spec.homepage = "https://gitee.com/sourceiOS/podfileDepDemo"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: podfileDep
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - WANGSHUAIPENG
7
+ - 王帅朋
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-18 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: iOS 端Podfile文件托管
41
+ description: iOS 依赖库使用yaml文件管理,并提供其他扩展功能
42
42
  email:
43
43
  - wsp810@163.com
44
44
  executables: []
@@ -59,18 +59,20 @@ files:
59
59
  - lib/podfileDep/check/module.rb
60
60
  - lib/podfileDep/check/xcodeproj.rb
61
61
  - lib/podfileDep/constants.rb
62
+ - lib/podfileDep/indirect/indirect.rb
62
63
  - lib/podfileDep/modify/modify_code.rb
63
64
  - lib/podfileDep/podfilelock.rb
64
65
  - lib/podfileDep/reference/project.rb
66
+ - lib/podfileDep/reference/uninstall.rb
65
67
  - lib/podfileDep/reference/unused.rb
66
68
  - lib/podfileDep/version.rb
67
69
  - lib/podfileDep/yaml/yaml_dep.rb
68
70
  - podfileDep.gemspec
69
71
  - release.sh
70
- homepage: https://gitee.com/sourceiOS/podfileDep
72
+ homepage: https://gitee.com/sourceiOS/podfileDepDemo
71
73
  licenses: []
72
74
  metadata:
73
- homepage_uri: https://gitee.com/sourceiOS/podfileDep
75
+ homepage_uri: https://gitee.com/sourceiOS/podfileDepDemo
74
76
  source_code_uri: https://gitee.com/sourceiOS/podfileDep
75
77
  changelog_uri: https://gitee.com/sourceiOS/podfileDep
76
78
  post_install_message:
@@ -91,5 +93,5 @@ requirements: []
91
93
  rubygems_version: 3.4.6
92
94
  signing_key:
93
95
  specification_version: 4
94
- summary: podfile依赖管理.
96
+ summary: iOS端 依赖库使用yaml文件管理
95
97
  test_files: []