cocoapods-dep 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58323a243d5394a94f39b1e145f9b4dea68a9ec6f034980b2ed38bb856f154e7
4
+ data.tar.gz: '0824dffad7eb6f3124a51359c8e6e8db6eaee1fb4df6612bee6f88f051f73920'
5
+ SHA512:
6
+ metadata.gz: f678b9f7ad69f42418b5780a5a6751472a0eee9823673bd02dd8ed9ef2934f2e8dc3092a73cdf56feba736bebf406d50c2f74e4b952512f3e8dc548fef23ad78
7
+ data.tar.gz: 78b20de6fa5cfcb31eef149d8bb8565727e3c1aa48a65e5c42301835c9784fbbf5d816fb24cc5124763c4efbf82c0b274143704b62b1b555fcd01106af478f29
@@ -0,0 +1 @@
1
+ require 'cocoapods-dep/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-dep/command/dep'
@@ -0,0 +1,234 @@
1
+ require 'pp'
2
+ require 'yaml'
3
+
4
+ module Pod
5
+ class Command
6
+ class Dep < Command
7
+ include Command::ProjectDirectory
8
+
9
+ self.summary = "分析podfile依赖"
10
+ self.description = <<-DESC
11
+ 分析podfile依赖,输出优先级.
12
+ DESC
13
+
14
+ # 输出依赖文件
15
+ OUTFILE = 'dep_analyze_out.lock'
16
+
17
+ def self.options
18
+ [].concat(super)
19
+ end
20
+
21
+ def self.arguments
22
+ [
23
+ CLAide::Argument.new('PODSPEC', false)
24
+ ].concat(super)
25
+ end
26
+
27
+ def initialize(argv)
28
+ @podspec_name = argv.shift_argument
29
+ super
30
+ end
31
+
32
+ def validate!
33
+ super
34
+ if @podspec_name
35
+ require 'pathname'
36
+ path = Pathname.new(@podspec_name)
37
+ if path.exist?
38
+ @podspec = Specification.from_file(path)
39
+ else
40
+ @podspec = SourcesManager.
41
+ search(Dependency.new(@podspec_name)).
42
+ specification.
43
+ subspec_by_name(@podspec_name)
44
+ end
45
+ end
46
+ end
47
+
48
+ def run
49
+ puts "开始分析依赖".green
50
+ yaml_write
51
+ puts "分析依赖完成,请查看 <-- #{Dir.pwd}/#{OUTFILE} -->文件".green
52
+ end
53
+
54
+ def arr_ele_cutout(arr)
55
+ arr.map do |ele|
56
+ if ele.to_s.include? '/'
57
+ ele.to_s[0, ele.index('/')]
58
+ else
59
+ ele
60
+ end
61
+ end
62
+ end
63
+
64
+ def dependencies
65
+ @dependencies ||= begin
66
+ analyzer = Installer::Analyzer.new(
67
+ sandbox,
68
+ podfile,
69
+ @podspec ? nil : config.lockfile
70
+ )
71
+
72
+ specs = config.with_changes(skip_repo_update: true) do
73
+ analyzer.analyze(@podspec).specs_by_target.values.flatten(1)
74
+ end
75
+
76
+ generate_pods_data(specs)
77
+ end
78
+ end
79
+
80
+ def generate_pods_data(specs)
81
+ pods_and_deps_merged = specs.reduce({}) do |result, spec|
82
+ name = spec.name
83
+ result[name] ||= []
84
+ result[name].concat(spec.all_dependencies.map(&:name))
85
+ result
86
+ end
87
+
88
+ pod_and_deps = pods_and_deps_merged.map do |name, deps|
89
+ deps.empty? ? name : { name => YAMLHelper.sorted_array(deps.uniq) }
90
+ end
91
+ YAMLHelper.sorted_array(pod_and_deps)
92
+ end
93
+
94
+ def podfile
95
+ @podfile ||= begin
96
+ if podspec = @podspec
97
+ platform = podspec.available_platforms.first
98
+ platform_name, platform_version = platform.name, platform.deployment_target.to_s
99
+ sources = SourcesManager.all.map(&:url)
100
+ pp sources
101
+ Podfile.new do
102
+ install! :cocoapods, integrate_targets: false
103
+ sources.each { |s| source s }
104
+ platform platform_name, platform_version
105
+ pod podspec.name, podspec: podspec.defined_in_file
106
+ end
107
+ else
108
+ verify_podfile_exists!
109
+ config.podfile
110
+ end
111
+ end
112
+ end
113
+
114
+ def sandbox
115
+ if @podspec
116
+ require 'tmpdir'
117
+ Sandbox.new(Dir.mktmpdir)
118
+ else
119
+ config.sandbox
120
+ end
121
+ end
122
+
123
+ def yaml_write
124
+ lock_path = config.installation_root.to_s + '/dependencies.lock'
125
+ write_to_disk(lock_path, dependencies)
126
+ read_change_dependencies_from_file(lock_path)
127
+ end
128
+
129
+ def write_to_disk(path, content)
130
+ File.open(path, 'w') { |f| f.write(content.to_yaml) }
131
+ end
132
+
133
+ def read_change_dependencies_from_file(path)
134
+ yaml_file = YAML.load(File.open(path))
135
+ lines = Array.new()
136
+
137
+ change_dependencies = Array.new()
138
+ CHANGE_DEPENDENCIES.each do |spec_name|
139
+ spec_dependency_hash = Hash.new()
140
+ spec_name_key = spec_name
141
+ spec_dependencies = Array.new()
142
+ yaml_file.each do |line|
143
+ if line.class == Hash
144
+ line.each { |key, value|
145
+ if key.to_s.include? spec_name.to_s or key.to_s.include? spec_name.to_s + '/'
146
+ spec_dependencies = spec_dependencies + value
147
+ end
148
+ }
149
+ end
150
+ end
151
+ spec_dependency_hash[spec_name_key] = arr_ele_cutout(spec_dependencies)
152
+ change_dependencies << spec_dependency_hash
153
+ end
154
+
155
+ dependencies_priority = Hash.new()
156
+ change_dependencies.each do |dependency|
157
+ dependency.each { |key, value|
158
+ temp_arr = value & CHANGE_DEPENDENCIES
159
+ if temp_arr.include? key
160
+ temp_arr.delete(key)
161
+ end
162
+ dependencies_priority[key] = temp_arr
163
+ }
164
+ end
165
+
166
+ temp_change_dependencies_priority = Hash.new()
167
+ while temp_change_dependencies_priority != CHANGE_DEPENDENCIES_PRIORITY do
168
+ temp_change_dependencies_priority = CHANGE_DEPENDENCIES_PRIORITY.clone
169
+ dependencies_priority.each { |key, value|
170
+ if value.length > 0
171
+ priority = CHANGE_DEPENDENCIES_PRIORITY[key]
172
+ value.each do |pod_name|
173
+ if priority >= CHANGE_DEPENDENCIES_PRIORITY[pod_name]
174
+ priority = CHANGE_DEPENDENCIES_PRIORITY[pod_name] - 1
175
+ end
176
+ end
177
+ CHANGE_DEPENDENCIES_PRIORITY[key] = priority
178
+ end
179
+ }
180
+ end
181
+ pp CHANGE_DEPENDENCIES_PRIORITY
182
+ write_to_disk(config.installation_root.to_s + '/' + OUTFILE, CHANGE_DEPENDENCIES_PRIORITY.to_yaml)
183
+ end
184
+
185
+ CHANGE_DEPENDENCIES = [
186
+ "GCTTravel",
187
+ "GCTUIKit",
188
+ "GCTIOSUtils",
189
+ "GCTAccount",
190
+ "GCTQuickLogin",
191
+ "GCTHTTPServer",
192
+ "GCTWiFiConnection",
193
+ "GCTStatistic",
194
+ "GCTShareKit",
195
+ "GCTMine",
196
+ "GCTReservation",
197
+ 'GCTCitiesAndStations',
198
+ 'GCTMapKitV2',
199
+ 'GCTSharedTravel',
200
+ 'GCTPromotionCenter',
201
+ 'GCTAudio',
202
+ 'GCTCinema',
203
+ 'GCTMediaPlayer',
204
+ 'GCTVideo',
205
+ 'GCTAdvert',
206
+ 'GCTCoupon'
207
+ ].map(&:freeze).freeze
208
+
209
+ CHANGE_DEPENDENCIES_PRIORITY = {
210
+ "GCTTravel"=> 1000,
211
+ "GCTUIKit"=> 1000,
212
+ "GCTIOSUtils"=> 1000,
213
+ "GCTAccount"=> 1000,
214
+ "GCTQuickLogin"=> 1000,
215
+ "GCTHTTPServer"=> 1000,
216
+ "GCTWiFiConnection"=> 1000,
217
+ "GCTStatistic"=> 1000,
218
+ "GCTShareKit"=> 1000,
219
+ "GCTMine"=> 1000,
220
+ "GCTReservation"=> 1000,
221
+ 'GCTCitiesAndStations'=> 1000,
222
+ 'GCTMapKitV2'=> 1000,
223
+ 'GCTSharedTravel'=> 1000,
224
+ 'GCTPromotionCenter'=> 1000,
225
+ 'GCTAudio'=> 1000,
226
+ 'GCTCinema'=> 1000,
227
+ 'GCTMediaPlayer'=> 1000,
228
+ 'GCTVideo'=> 1000,
229
+ 'GCTAdvert'=> 1000,
230
+ 'GCTCoupon'=> 1000
231
+ }
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsDep
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ # hook管理注册器,这个文件用来注册hook的pod方法
2
+ # 参考https://www.dazhuanlan.com/2019/11/19/5dd30f005575f/
3
+ require 'cocoapods-dep/command'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-dep
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - jieming
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-dep.
42
+ email:
43
+ - 307113345@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-dep.rb
49
+ - lib/cocoapods-dep/command.rb
50
+ - lib/cocoapods-dep/command/dep.rb
51
+ - lib/cocoapods-dep/gem_version.rb
52
+ - lib/cocoapods_plugin.rb
53
+ homepage: https://gi-dev.ccrgt.com/ios-thirdpart/cocoapods-dep
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A longer description of cocoapods-dep.
76
+ test_files: []