podfileDep 2.6.0 → 2.7.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: e48070d532b39c76d3f4f7084952916e280eb3eca8c2bfd1dae6cb834dd36c99
4
- data.tar.gz: db121163f7c02f5d13215452f22936d160bb3daada7463564cebdd4744f6d6f0
3
+ metadata.gz: 0d32097193876845e685b951363a7b4476654390db321ffbed66677c5e056184
4
+ data.tar.gz: 10b832fbc8d5ec05f36f11f6b6a9603cb2bfcc22d51f96b3bde839251b8d2d35
5
5
  SHA512:
6
- metadata.gz: 14a499d954f0ed310ece1893dd7c97e196f82422a077f1d53c06bb4db96359a313e687be57dde9827c474c86c127d6b5d785bb82228b67234df1f861fa80d63b
7
- data.tar.gz: c87b284a26fec791c69160228e54896e58cb42a7a376745a7649e8fd47fb3978af0dd1eeffdcfabac1c9f599e86e604c8870c8f59e7f564558d3ce7ec97c766f
6
+ metadata.gz: 6135afcbd4cac979bb16cf41152c0f0c02a16e2ce33f6931f02afe446938164cfcd919f85115da1a45845508b0e0e9e0bc4f9d834f056e0e2a1ca7e5433608cd
7
+ data.tar.gz: 3ac770ccd5ce158c71b1b5c3c018d34a465881868da6adef69b0b11831197454682fc8258a8a323576f346b7785553070166261873090da46e6cc898c7503f51
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  ## [Released]
2
+ ### [2.7.0] - 2024-08-08
3
+ - 新增功能反转依赖的查询和打印pod dep
4
+
2
5
  ### [2.6.0] - 2024-07-17
3
6
  - 新增命令pod install all
4
7
 
@@ -1,5 +1,6 @@
1
1
  require 'cocoapods'
2
- require_relative 'podfileDep/command/all'
2
+ require_relative 'podfileDep/command/dep'
3
+ require_relative 'podfileDep/command/quick'
3
4
  require_relative 'podfileDep/command/quick'
4
5
  require_relative 'podfileDep/check/project'
5
6
  require_relative 'podfileDep/check/podspec'
@@ -0,0 +1,36 @@
1
+ require_relative '../dep/find'
2
+ require_relative '../version'
3
+ module Pod
4
+ class Command
5
+ class Dep < Command
6
+
7
+ self.summary = '从Podfile.lock文件里检索出依赖反转后的情况'
8
+
9
+ self.description = <<-DESC
10
+ 从Podfile.lock文件里检索出依赖反转后的情况
11
+ DESC
12
+
13
+ def self.options
14
+ [
15
+ %w[--name=xx xx为要查询的组件的名字],
16
+ %w[--sort 输出反转依赖时按数量从小到大排序],
17
+ ].concat(super).reject { |(name, _)| (name == '--no-ansi' or name == '--silent' or name == '--allow-root' or name == '--verbose') }
18
+ end
19
+
20
+ def initialize(argv)
21
+ super
22
+ puts "插件版本号: #{PodfileDep::VERSION}"
23
+ @name = argv.option('name')
24
+ @sort_count = argv.flag?('sort', false)
25
+ end
26
+
27
+ def run
28
+ verify_lockfile_exists!
29
+ finder = Pod::DepFinder.new
30
+ finder.find_name = @name
31
+ finder.sort_count = @sort_count
32
+ finder.find
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,118 @@
1
+ require 'yaml'
2
+
3
+ module Pod
4
+ class DepFinder
5
+
6
+ # @param [Hash] podfileLock内容
7
+ attr_accessor :lockfile_content
8
+
9
+ # @param [String] 要查询的组件名
10
+ attr_accessor :find_name
11
+
12
+ # @param [bool] 是否按数量从小到大排序
13
+ attr_accessor :sort_count
14
+
15
+ def initialize
16
+ super
17
+ init_lock
18
+ end
19
+
20
+ def init_lock
21
+ # 读取名为Podfile.lock的yaml文件, 并通过分析里面的PODS数组,输出依赖的第三方库的名字
22
+ unless File.exist?("Podfile.lock")
23
+ puts "Podfile.lock文件不存在,请先执行pod install或pod update"
24
+ end
25
+
26
+ @sort_count = false
27
+
28
+ @lockfile_content = YAML.load_file('Podfile.lock')
29
+
30
+ end
31
+
32
+ # @api 反向依赖查询
33
+ def find
34
+
35
+ if @find_name
36
+ find_for_name
37
+ else
38
+ find_all
39
+ end
40
+ end
41
+
42
+ def find_all
43
+
44
+ reverse_map = Hash.new
45
+ # 循环遍历lockfile对象中的PODS数组
46
+ @lockfile_content['PODS'].each do |pod|
47
+ # 拿到所有的组件名
48
+ key = pod.is_a?(Hash) ? pod.keys[0] : pod
49
+ key = key.split(" (")[0]
50
+ results = find_with_name(key)
51
+
52
+ reverse_map[key] = results
53
+
54
+ end
55
+
56
+ puts ""
57
+ sorted_hash = reverse_map
58
+ if @sort_count
59
+ puts "反转后依赖如下(数量从少到多):"
60
+ sorted_hash = Hash[reverse_map.sort_by { |key, value| value.length }]
61
+ else
62
+ puts "反转后依赖如下:"
63
+ end
64
+
65
+ sorted_hash.each do |key, array|
66
+ puts "依赖#{key}的组件有(#{array.length}个):"
67
+ array.each do |obj|
68
+ puts obj
69
+ end
70
+ puts "\n"
71
+ end
72
+
73
+ unless @sort_count
74
+ puts "==> 按数量从少到多排序,可使用pod dep --sort"
75
+ end
76
+ puts "==> 查询单个依赖的情况,可使用pod dep --name=xx"
77
+ end
78
+
79
+ def find_for_name
80
+ results = find_with_name(@find_name)
81
+
82
+ if results.empty?
83
+ puts "组件#{@find_name}没有被任何其他组件依赖"
84
+ return
85
+ end
86
+
87
+ puts "依赖#{@find_name}的组件有:"
88
+ results.each do |res|
89
+ puts res
90
+ end
91
+ end
92
+
93
+ def find_with_name(name)
94
+ results = Array.new
95
+ # 循环遍历lockfile对象中的PODS数组
96
+ @lockfile_content['PODS'].each do |pod|
97
+ if pod.is_a?(Hash)
98
+ pod.values.each do |value|
99
+ # 如果value是一个数组,则判断数组中是否包含name
100
+ if value.is_a?(Array)
101
+ value.each { |sub_value|
102
+ # 这里的处理包含了子模块的情况
103
+ sub_module = sub_value.split(" (")[0]
104
+ if sub_module == name
105
+ results << pod.keys.first
106
+ end
107
+ }
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ # 去重
114
+ results.uniq
115
+ end
116
+ end
117
+ end
118
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PodfileDep
4
- VERSION = "2.6.0"
4
+ VERSION = "2.7.0"
5
5
  end
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.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 王帅朋
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-17 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -75,7 +75,9 @@ files:
75
75
  - lib/podfileDep/check/util.rb
76
76
  - lib/podfileDep/check/xcodeproj.rb
77
77
  - lib/podfileDep/command/all.rb
78
+ - lib/podfileDep/command/dep.rb
78
79
  - lib/podfileDep/command/quick.rb
80
+ - lib/podfileDep/dep/find.rb
79
81
  - lib/podfileDep/indirect/indirect.rb
80
82
  - lib/podfileDep/modify/modify_code.rb
81
83
  - lib/podfileDep/my_constants.rb