Skip to content

Commit

Permalink
Support package visualization in bin/packs (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Evanczuk authored Nov 10, 2022
1 parent 048e5d4 commit 49798f0
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 200 deletions.
15 changes: 12 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
use_packwerk (0.60.1)
use_packwerk (0.61.0)
code_ownership
colorize
package_protections
Expand All @@ -11,6 +11,7 @@ PATH
sorbet-runtime
thor
tty-prompt
visualize_packwerk

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -61,7 +62,7 @@ GEM
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
package_protections (3.0.0)
package_protections (4.0.0)
activesupport
parse_packwerk
rubocop
Expand Down Expand Up @@ -130,7 +131,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-packs (0.0.13)
rubocop-packs (0.0.17)
activesupport
parse_packwerk
rubocop
Expand All @@ -140,6 +141,8 @@ GEM
rubocop (~> 1.33)
rubocop-sorbet (0.6.11)
rubocop (>= 0.90.0)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
smart_properties (1.17.0)
sorbet (0.5.9962)
Expand Down Expand Up @@ -184,6 +187,12 @@ GEM
unparser (0.6.5)
diff-lcs (~> 1.3)
parser (>= 3.1.0)
visualize_packwerk (0.0.6)
code_ownership
parse_packwerk
rake
ruby-graphviz
sorbet-runtime
webrick (1.7.0)
wisper (2.0.1)
yard (0.9.27)
Expand Down
29 changes: 29 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path('bundle', __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rubocop', 'rubocop')
29 changes: 29 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path('bundle', __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('tapioca', 'tapioca')
1 change: 1 addition & 0 deletions lib/use_packwerk/private/interactive_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require 'use_packwerk/private/interactive_cli/use_cases/validate'
require 'use_packwerk/private/interactive_cli/use_cases/regenerate_rubocop_todo'
require 'use_packwerk/private/interactive_cli/use_cases/lint_package_yml'
require 'use_packwerk/private/interactive_cli/use_cases/visualize'

module UsePackwerk
module Private
Expand Down
44 changes: 44 additions & 0 deletions lib/use_packwerk/private/interactive_cli/use_cases/visualize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# typed: strict

require 'visualize_packwerk'

module UsePackwerk
module Private
module InteractiveCli
module UseCases
class Visualize
extend T::Sig
extend T::Helpers
include Interface

sig { override.params(prompt: TTY::Prompt).void }
def perform!(prompt)
teams_or_packs = prompt.select('Do you want the graph nodes to be teams or packs?', %w[Teams Packs])

if teams_or_packs == 'Teams'
teams = TeamSelector.multi_select(prompt)
VisualizePackwerk.team_graph!(teams)
else
by_name_or_by_owner = prompt.select('Do you select packs by name or by owner?', ['By name', 'By owner'])
if by_name_or_by_owner == 'By owner'
teams = TeamSelector.multi_select(prompt)
selected_packs = ParsePackwerk.all.select do |p|
teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
end
else
selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
end

VisualizePackwerk.package_graph!(selected_packs)
end
end

sig { override.returns(String) }
def user_facing_name
'Visualize pack relationships'
end
end
end
end
end
end
Loading

0 comments on commit 49798f0

Please sign in to comment.