visualize_packs 0.5.19 → 0.5.20

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: 21c174ca9487c1d11560c585972f1da5ff9b8ddc53148537753af82d1fb66a25
4
- data.tar.gz: 2b910b38ad69c3df0631a98b21ec4ca6651190ab973bfc4ba4692e0f1fb7d740
3
+ metadata.gz: b8efefa896a6d002c7333dad53f2a8fa0be10d8c0004895682239c7a7f6a1105
4
+ data.tar.gz: 0046a3a518c25de488b4b2e0d89c04ced6e45c1ff5d90e9e85d71d46b5256e89
5
5
  SHA512:
6
- metadata.gz: 883ddfb826a9f9051b0431d289fd98b6a92d41c41a42f4e560c0fae89a9432e741c5d9fddd2802a9eae64c9c1a6073d541f26ca8269c40d7f27b946908881088
7
- data.tar.gz: 6136452d922cefa21486b40c18b2df6fda1838f25030d66019edfd291101dcae503777f7ecc9581ccf07d0c894f5800adc44248a18b931359d2ab2e1eb65d727
6
+ metadata.gz: 5282d8a1af4103a3d6c38675c378adee512029eb4320a29874b91463c2fc4aa7380a76165306f8dc2d8163b67e60875b2496aeacca209b40ebdb09217744888c
7
+ data.tar.gz: 99f84713ec95080f82668184bd69ce4e67dc30fbc739803f67efe8ebbe51728dbd4717d22eec946a2e24ce1128cd646d3cca47413a09a481718b76c029c47ae7
data/bin/visualize_packs CHANGED
@@ -34,6 +34,13 @@ OptionParser.new do |opt|
34
34
 
35
35
  opt.on('--title=STRING', "Set a custom diagram title") { |o| options.title = o }
36
36
 
37
+ opt.on('-V', '--version', "Show version") do
38
+ spec_path = File.expand_path("../visualize_packs.gemspec", __dir__)
39
+ spec = Gem::Specification::load(spec_path)
40
+ puts "Version #{spec.version}"
41
+ exit
42
+ end
43
+
37
44
  opt.on_tail("-h", "--help", "Show this message") do
38
45
  puts opt
39
46
  exit
@@ -70,25 +70,31 @@ module VisualizePacks
70
70
  def self.diagram_title(options, max_todo_count)
71
71
  return "<<b>#{options.title}</b>>" if options.title
72
72
 
73
- app_name = File.basename(Dir.pwd)
74
- focus_edge_info = options.focus_pack && options.show_only_edges_to_focus_pack != FocusPackEdgeDirection::All ? "showing only edges to/from focus pack" : "showing all edges between visible packs"
75
- focus_info = options.focus_pack ? "Focus on #{limited_sentence(options.focus_pack)} (#{focus_edge_info})" : "All packs"
76
- skipped_info =
77
- [
78
- options.show_legend ? nil : "hiding legend",
79
- options.show_layers ? nil : "hiding layers",
80
- options.show_dependencies ? nil : "hiding dependencies",
81
- options.show_todos ? nil : "hiding todos",
82
- EdgeTodoTypes.values.size == options.only_todo_types.size ? nil : "only #{limited_sentence(options.only_todo_types.map &:serialize)} todos",
83
- options.show_privacy ? nil : "hiding privacy",
84
- options.show_teams ? nil : "hiding teams",
85
- options.show_visibility ? nil : "hiding visibility",
86
- options.roll_nested_into_parent_packs ? "hiding nested packs" : nil,
87
- options.show_nested_relationships ? nil : "hiding nested relationships",
88
- options.exclude_packs.empty? ? nil : "excluding pack#{options.exclude_packs.size > 1 ? 's' : ''}: #{limited_sentence(options.exclude_packs)}",
73
+ focus_info = if options.focus_pack
74
+ "Focus on #{limited_sentence(options.focus_pack)} (Edge mode: #{options.show_only_edges_to_focus_pack.serialize})"
75
+ else
76
+ "All packs"
77
+ end
78
+
79
+ hidden_aspects = [
80
+ options.show_legend ? nil : "legend",
81
+ options.show_layers ? nil : "layers",
82
+ options.show_dependencies ? nil : "dependencies",
83
+ options.show_todos ? nil : "todos",
84
+ options.show_privacy ? nil : "privacy",
85
+ options.show_teams ? nil : "teams",
86
+ options.show_visibility ? nil : "visibility",
87
+ options.roll_nested_into_parent_packs ? "nested packs" : nil,
88
+ options.show_nested_relationships ? nil : "nested relationships",
89
89
  ].compact.join(', ').strip
90
- main_title = "#{app_name}: #{focus_info}#{skipped_info != '' ? ' - ' + skipped_info : ''}"
91
- sub_title = ""
90
+ hidden_aspects_title = hidden_aspects != '' ? "Hiding #{hidden_aspects}" : nil
91
+
92
+ todo_types = EdgeTodoTypes.values.size == options.only_todo_types.size ? nil : "Only #{options.only_todo_types.map &:serialize} todos",
93
+
94
+ exclusions = options.exclude_packs.empty? ? nil : "Excluding pack#{options.exclude_packs.size > 1 ? 's' : ''}: #{limited_sentence(options.exclude_packs)}",
95
+
96
+ main_title = [focus_info, hidden_aspects_title, todo_types, exclusions].compact.join('. ')
97
+
92
98
  if options.show_todos && max_todo_count
93
99
  sub_title = "<br/><font point-size='12'>Widest todo edge is #{max_todo_count} todo#{max_todo_count > 1 ? 's' : ''}</font>"
94
100
  end
@@ -115,6 +121,8 @@ module VisualizePacks
115
121
  case options.show_only_edges_to_focus_pack
116
122
  when FocusPackEdgeDirection::All then
117
123
  true
124
+ when FocusPackEdgeDirection::None then
125
+ match_packs?(start_node, options.focus_pack) && match_packs?(end_node, options.focus_pack)
118
126
  when FocusPackEdgeDirection::InOut then
119
127
  match_packs?(start_node, options.focus_pack) || match_packs?(end_node, options.focus_pack)
120
128
  when FocusPackEdgeDirection::In then
@@ -200,36 +208,32 @@ module VisualizePacks
200
208
  result = T.let([], T::Array[T.nilable(String)])
201
209
  result = packages.map { |pack| pack.name }
202
210
 
203
- if focus_pack && !focus_pack.empty?
211
+ if focus_pack
204
212
  result = []
205
- result += packages.map { |pack| pack.name }.select { |p| match_packs?(p, focus_pack) }
206
- if options.show_dependencies
207
- result += packages.select { |p| p.dependencies.any? { |d| match_packs?(d, focus_pack) }}.map { |pack| pack.name }
208
- end
209
- if options.show_todos && [FocusPackEdgeDirection::All, FocusPackEdgeDirection::In, FocusPackEdgeDirection::InOut].include?(options.show_only_edges_to_focus_pack)
210
- result += packages.select do
211
- |p| (p.violations || []).inject([]) do |res, todo|
212
- res << todo.to_package_name if options.only_todo_types.include?(EdgeTodoTypes.deserialize(todo.type))
213
- res
214
- end.any? { |v| match_packs?(v, focus_pack) }
215
- end.map { |pack| pack.name }
213
+ focus_pack_name = packages.map { |pack| pack.name }.select { |p| match_packs?(p, focus_pack) }
214
+ result += focus_pack_name
215
+
216
+ dependents = options.show_dependencies ? dependents_on(packages, focus_pack_name) : []
217
+ dependencies = options.show_dependencies ? dependencies_of(packages, focus_pack_name) : []
218
+ todos_out = options.show_todos ? todos_out(packages, focus_pack_name, options) : []
219
+ todos_in = options.show_todos ? todos_in(packages, focus_pack_name, options) : []
220
+
221
+ case options.show_only_edges_to_focus_pack
222
+ when FocusPackEdgeDirection::All, FocusPackEdgeDirection::InOut then
223
+ result += dependents + dependencies + todos_out + todos_in
224
+ when FocusPackEdgeDirection::In then
225
+ result += dependents + todos_in
226
+ when FocusPackEdgeDirection::Out then
227
+ result += dependencies + todos_out
228
+ when FocusPackEdgeDirection::None then
229
+ # nothing to do
216
230
  end
217
- packages.map { |pack| pack.name }.select { |p| match_packs?(p, focus_pack) }.each do |p|
218
- if options.show_dependencies
219
- result += packages_by_name[p].dependencies
220
- end
221
- if options.show_todos && [FocusPackEdgeDirection::All, FocusPackEdgeDirection::Out, FocusPackEdgeDirection::InOut].include?(options.show_only_edges_to_focus_pack)
222
- result += (packages_by_name[p].violations || []).inject([]) do |res, todo|
223
- res << todo.to_package_name if options.only_todo_types.include?(EdgeTodoTypes.deserialize(todo.type))
224
- res
225
- end
226
- end
227
- end
228
- result = result.uniq
231
+
229
232
  parent_packs = result.inject([]) do |res, package_name|
230
233
  res << nested_packages[package_name]
231
234
  res
232
235
  end
236
+
233
237
  result = (result + parent_packs).uniq.compact
234
238
  end
235
239
 
@@ -318,4 +322,39 @@ module VisualizePacks
318
322
  def self.match_packs?(pack, packs_name_with_wildcards)
319
323
  !packs_name_with_wildcards || packs_name_with_wildcards.any? {|p| File.fnmatch(p, pack)}
320
324
  end
325
+
326
+ sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String]).returns(T::Array[String]) }
327
+ def self.dependencies_of(all_packages, focus_packs_names)
328
+ focus_packs = all_packages.select { focus_packs_names.include?(_1.name)}
329
+
330
+ focus_packs.inject([]) do |result, pack|
331
+ result += pack.dependencies
332
+ result
333
+ end.uniq
334
+ end
335
+
336
+ sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String]).returns(T::Array[String]) }
337
+ def self.dependents_on(all_packages, focus_packs_names)
338
+ all_packages.select { |pack| pack.dependencies.any? { focus_packs_names.include?(_1) }}.map &:name
339
+ end
340
+
341
+ sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String], options: Options).returns(T::Array[String]) }
342
+ def self.todos_in(all_packages, focus_packs_names, options)
343
+ all_packages.select do |p|
344
+ (p.violations || []).inject([]) do |res, todo|
345
+ res << todo.to_package_name if options.only_todo_types.include?(EdgeTodoTypes.deserialize(todo.type))
346
+ res
347
+ end.any? { |v| focus_packs_names.include?(v) }
348
+ end.map { |pack| pack.name }
349
+ end
350
+
351
+ sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String], options: Options).returns(T::Array[String]) }
352
+ def self.todos_out(all_packages, focus_packs_names, options)
353
+ all_packages.inject([]) do |result, p|
354
+ focus_packs_names.include?(p.name) && (p.violations || []).each do |todo|
355
+ result << todo.to_package_name if options.only_todo_types.include?(EdgeTodoTypes.deserialize(todo.type))
356
+ end
357
+ result
358
+ end
359
+ end
321
360
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visualize_packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.19
4
+ version: 0.5.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-08 00:00:00.000000000 Z
11
+ date: 2023-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler