check_dependencies 0.1.5 → 0.1.6

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: 607fd112ebc8ea3a0afad3ec92bcf7d600edf0be1bf905e43e7960660220c164
4
- data.tar.gz: c7387bb2582daf0f9b7eaf32c201ae724f40eee327e8653e5fd0dc79fece8073
3
+ metadata.gz: 80d283805b19f7e30c9f5657d943d3722c8409ead45fd07d20f48b05c47896f3
4
+ data.tar.gz: 885f110feaba05424b3d8b7ea66e247b8bfd4e9d58dfe10438813780a496a157
5
5
  SHA512:
6
- metadata.gz: f7bc472950ed8444f1616a90fcbc781afbfb2f826eb4e077305066fb0c0ae059a872ef47a130d241e3fd055d5b272ceaa7d188d06f33f8b8faf10b65990d9c80
7
- data.tar.gz: 316f13bee5fc54d1cc208c0e0f44b5b684332aceb97498c059422e40691583078db05fa0cf8ff16ed8f2fb67122844b099ba86b89410e645cc157ba27329a935
6
+ metadata.gz: 29c222014394b966205155a88364f04007011700878abab9c88fab9a5a5b5408bde9e30affebeece3a746904aeaea72d823fb31337c07f181fc84897a8562427
7
+ data.tar.gz: 671db52a03bc1b40e37e6a905d1627982d18a25eac0ba0918ac5eb12ecad2f77b48d2c3dafad00d14878697c0a570b04587d1f6e6da76f13a9c3ee61976727c3
@@ -1,5 +1,81 @@
1
1
 
2
2
  #!/usr/bin/env ruby
3
+ # Usage Hint
4
+ require 'optparse'
5
+ require 'json'
6
+ require 'set'
7
+
8
+ # Method to check for required options and print usage if missing
9
+ def check_required_options(options, required_keys, parser)
10
+ missing_options = required_keys.select { |key| options[key].nil? }
11
+ unless missing_options.empty?
12
+ puts "Missing required options: #{missing_options.join(', ')}"
13
+ puts parser
14
+ exit
15
+ end
16
+ end
17
+
18
+ # Define and parse options based on the command
19
+ options = {}
20
+ global_options = OptionParser.new do |opts|
21
+ opts.banner = "Usage: script.rb [command] [options]"
22
+ opts.separator ""
23
+ opts.separator "Commands:"
24
+ opts.separator " gen_pod: Generate podfile entries for new dependencies"
25
+ opts.separator " dif_pod: Generate differences between Podfile.lock files"
26
+ opts.separator ""
27
+ opts.separator "For command-specific help, run: check_dependencies [command] --help"
28
+ end
29
+
30
+ gen_pod_config_string = <<~CONFIG
31
+ {
32
+ "A": {
33
+ "branch": "release",
34
+ "path": "XXXXXXXXXXXXXXX",
35
+ "git_url": "XXXXXXXXXXXXXXX"
36
+ },
37
+ "B": {
38
+ "branch": "release",
39
+ "path": "XXXXXXXXXXXXXXX",
40
+ "git_url": "XXXXXXXXXXXXXXX"
41
+ },
42
+ }
43
+ CONFIG
44
+
45
+ dif_pod_config_string = <<~CONFIG
46
+ [
47
+ "A",
48
+ "B"
49
+ ]
50
+ CONFIG
51
+
52
+
53
+ command = ARGV.shift
54
+ case command
55
+ when "gen_pod"
56
+ command_options = OptionParser.new do |opts|
57
+ opts.banner = "Usage: gen_pod --lockPath LOCK_PATH --depWay DEP_WAY [--configPath CONFIG_PATH]"
58
+ opts.on("--lockPath LOCK_PATH", String, "Specify the Podfile.lock path") { |v| options[:lockPath] = v }
59
+ opts.on("--depWay DEP_WAY", String, "Specify the depWay parameter (path or branch)") { |v| options[:depWay] = v }
60
+ opts.on("--configPath CONFIG_PATH", String, "Specify the path to repo_configs\n\n\n repo_configs examples:\n#{gen_pod_config_string}") { |v| options[:configPath] = v }
61
+ end.parse!(ARGV)
62
+ check_required_options(options, [:lockPath, :depWay, :configPath], command_options)
63
+
64
+ when "dif_pod"
65
+ command_options = OptionParser.new do |opts|
66
+ opts.banner = "Usage: dif_pod --oldLockPath OLD_LOCK_PATH --newLockPath NEW_LOCK_PATH [--configPath CONFIG_PATH]"
67
+ opts.on("--oldLockPath OLD_LOCK_PATH", String, "Specify old Podfile.lock path") { |v| options[:oldLockPath] = v }
68
+ opts.on("--newLockPath NEW_LOCK_PATH", String, "Specify new Podfile.lock path") { |v| options[:newLockPath] = v }
69
+ opts.on("--configPath CONFIG_PATH", String, "Specify the path of conf which contains dif libs (optional) \n\n\n repo_configs examples:\n#{dif_pod_config_string}") { |v| options[:configPath] = v }
70
+ end.parse!(ARGV)
71
+ check_required_options(options, [:oldLockPath, :newLockPath], command_options)
72
+
73
+ else
74
+ puts global_options
75
+ exit
76
+ end
77
+
78
+
3
79
  # Analyzes the Podfile.lock content to extract pod dependencies
4
80
  def analyze_podfile_lock(podfile_lock_content)
5
81
  unless podfile_lock_content.is_a?(String)
@@ -160,69 +236,72 @@ def generate_map_path_podfiles(lockPath, repo_configs)
160
236
  podfile_entrys.join("\n")
161
237
  end
162
238
 
163
- require 'optparse'
164
- require 'json'
165
239
 
166
- options = {}
167
- OptionParser.new do |opts|
168
- opts.banner = "Usage: check_dependencies --lockPath LOCK_PATH --depWay DEP_WAY --configPath CONFIG_PATH"
240
+ def colorize(text, color_code)
241
+ "\e[#{color_code}m#{text}\e[0m"
242
+ end
243
+ def red(text); colorize(text, 31); end
244
+ def green(text); colorize(text, 32); end
169
245
 
170
- opts.on("--lockPath LOCK_PATH", "Specify the Podfile.lock path") do |lockPath|
171
- options[:lockPath] = lockPath
246
+ def read_json_array_from_file_as_set(file_path)
247
+ # 确保文件存在
248
+ if File.exist?(file_path)
249
+ # 读取文件内容
250
+ file_content = File.read(file_path)
251
+ # 解析 JSON 字符串为 Ruby 数组
252
+ json_array = JSON.parse(file_content)
253
+ # 将数组转换为 Set 并返回
254
+ return json_array.to_set
255
+ else
256
+ puts "File not found: #{file_path}"
257
+ exit
172
258
  end
259
+ rescue JSON::ParserError => e
260
+ puts "Error parsing JSON from #{file_path}: #{e.message}"
261
+ exit
262
+ end
173
263
 
174
- opts.on("--depWay DEP_WAY", "Specify the depWay parameter (path or branch)") do |depWay|
175
- options[:depWay] = depWay
176
- end
264
+ def compare_podfile_locks(old_lock_path, new_lock_path, config_path = nil)
265
+ config_set = read_json_array_from_file_as_set(config_path)
266
+
267
+ old_pods = read_local_podfile_lock(old_lock_path)
268
+ new_pods = read_local_podfile_lock(new_lock_path)
177
269
 
178
- # repo_configs examples
179
- config_string = <<~CONFIG
180
- repo_configs = {
181
- 'Lib1' => {
182
- "branch" => "dev1",
183
- "path" => "/Users/xxxxxxxxx/xxxxlib",
184
- "git_url" => "xxxxxxxxxxxxxxxxxx"
185
- },
186
- 'Lib2' => {
187
- "branch" => "dev2",
188
- "path" => "/Users/xxxxxxxxx/xxxxlib",
189
- "git_url" => "xxxxxxxxxxxxxxxxxx"
190
- },
191
- 'Lib3' => {
192
- "branch" => "dev3",
193
- "path" => "/Users/xxxxxxxxx/xxxxlib",
194
- "git_url" => "xxxxxxxxxxxxxxxxxx"
195
- }
196
- }
197
- CONFIG
270
+ old_unique_deps = find_shortest_paths(extract_unique_dependencies(old_pods)).to_set
271
+ new_unique_deps = find_shortest_paths(extract_unique_dependencies(new_pods)).to_set
272
+ if !config_set.empty?
273
+ old_unique_deps = old_unique_deps.select { |dep| config_set.include?(dep.split('/').first) }
274
+ new_unique_deps = new_unique_deps.select { |dep| config_set.include?(dep.split('/').first) }
275
+ end
276
+ only_in_old = old_unique_deps - new_unique_deps
277
+ only_in_new = new_unique_deps - old_unique_deps
198
278
 
199
- opts.on("--configPath CONFIG_PATH", "Specify the path to repo_configs\n\n\n repo_configs examples:\n #{config_string}") do |configPath|
200
- options[:configPath] = configPath
279
+ # 检查差异并决定退出状态
280
+ if only_in_old.empty? && only_in_new.empty?
281
+ puts "没有差异,成功退出"
282
+ exit 0
283
+ else
284
+ puts "存在差异:"
285
+ only_in_old.each { |dep| puts "#{red('-')} #{dep}" }
286
+ only_in_new.each { |dep| puts "#{green('+')} #{dep}" }
287
+ exit 1
201
288
  end
202
- end.parse!
203
-
204
- # Check if all required arguments were provided
205
- if options[:lockPath].nil? || options[:depWay].nil? || options[:configPath].nil?
206
- puts "Please provide lockPath, depWay, and configPath parameters.\n you can run:\n check_dependencies --help "
207
- exit
208
289
  end
209
290
 
210
- # Function to read and parse the repo_configs.txt file
211
- def read_repo_configs(config_path)
212
- content = File.read(config_path)
213
- eval(content) # Using eval to parse the Ruby hash from the file, be cautious with its use!
214
- rescue
215
- puts "Failed to read or parse the repo_configs from #{config_path}"
216
- exit
291
+ if command == "gen_pod"
292
+ file_content = File.read(options[:configPath])
293
+ puts file_content
294
+ repo_configs =JSON.parse(file_content)
295
+ puts repo_configs
296
+ # Calls before pod install complete
297
+ if options[:depWay] == "path"
298
+ generate_map_path_podfiles(options[:lockPath], repo_configs)
299
+ elsif options[:depWay] == "branch"
300
+ generate_map_branch_podfiles(options[:lockPath], repo_configs)
301
+ else
302
+ puts "Invalid argument. Please provide 'path' or 'branch'."
303
+ end
304
+ elsif command == "dif_pod"
305
+ compare_podfile_locks(options[:oldLockPath], options[:newLockPath], options[:configPath])
217
306
  end
218
307
 
219
- repo_configs = read_repo_configs(options[:configPath])
220
-
221
- # Calls before pod install complete
222
- if options[:depWay] == "path"
223
- generate_map_path_podfiles(options[:lockPath], repo_configs)
224
- elsif options[:depWay] == "branch"
225
- generate_map_branch_podfiles(options[:lockPath], repo_configs)
226
- else
227
- puts "Invalid argument. Please provide 'path' or 'branch'."
228
- end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "check_dependencies"
3
- spec.version = "0.1.5"
3
+ spec.version = "0.1.6"
4
4
  spec.authors = ["ITxiansheng"]
5
5
  spec.email = ["itxiansheng@gmail.com"]
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITxiansheng