diff --git a/Gemfile.lock b/Gemfile.lock index 805f558..73598af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - visualize_packwerk (0.0.5) + visualize_packwerk (0.0.6) code_ownership parse_packwerk rake diff --git a/README.md b/README.md index 12ee36b..ab85e27 100644 --- a/README.md +++ b/README.md @@ -3,30 +3,25 @@ This gem contains rake tasks to help visualize relationships between packwerk packs. # Usage -## Building a package graph for a selection of packages (owned by 5 teams max) -``` -bin/rails visualize_packwerk:package_relationships['packs/pack1','packs/pack2'] +## Building a package graph for a selection of packages +```ruby +# Select the packs you want to include +selected_packs = ParsePackwerk.all +selected_packs = ParsePackwerk.all.select{|p| ['packs/my_pack_1', 'packs/my_pack_2'].include?(p.name) } +selected_packs = ParsePackwerk.all.select{|p| ['Team 1', 'Team 2'].include?(CodeOwnership.for_package(p)&.name) } +VisualizePackwerk.package_graph!(selected_packs) ``` -# Building a package graph for specific teams (5 teams max) +# Building a team graph for specific teams ``` -bin/rails visualize_packwerk:package_relationships_for_teams['Team1','Team2'] +# Select the teams you want to include +selected_teams = CodeTeams.all +selected_teams = CodeTeams.all.select{ ... } +VisualizePackwerk.team_graph!(selected_teams) ``` -# Building a package graph for all packages (this is slow and produces a huge file) -``` -bin/rails visualize_packwerk:package_relationships -``` - -# Building a TEAM graph for specific teams -``` -bin/rails visualize_packwerk:team_relationships['Team1','Team2'] -``` - -# Building a TEAM graph for all teams (this is slow and produces a huge file) -``` -bin/rails visualize_packwerk:team_relationships -``` +## bin/packs +For simpler use, use `bin/packs` in `use_packwerk` (https://github.com/rubyatscale/use_packwerk) # Want to change something or add a feature? Submit a PR or post an issue! diff --git a/lib/visualize_packwerk.rb b/lib/visualize_packwerk.rb index 4cbc244..430b65d 100644 --- a/lib/visualize_packwerk.rb +++ b/lib/visualize_packwerk.rb @@ -1,16 +1,28 @@ # typed: strict +require 'parse_packwerk' +require 'code_ownership' +require 'graphviz' +require 'sorbet-runtime' + +require 'visualize_packwerk/node_interface' +require 'visualize_packwerk/graph_interface' +require 'visualize_packwerk/team_node' +require 'visualize_packwerk/package_node' +require 'visualize_packwerk/team_graph' +require 'visualize_packwerk/package_graph' +require 'visualize_packwerk/package_relationships' + module VisualizePackwerk - require 'visualize_packwerk/railtie' if defined?(Rails) - require 'parse_packwerk' - require 'code_ownership' - require 'graphviz' + extend T::Sig + + sig { params(packages: T::Array[ParsePackwerk::Package]).void } + def self.package_graph!(packages) + PackageRelationships.new.create_package_graph!(packages) + end - require 'visualize_packwerk/node_interface' - require 'visualize_packwerk/graph_interface' - require 'visualize_packwerk/team_node' - require 'visualize_packwerk/package_node' - require 'visualize_packwerk/team_graph' - require 'visualize_packwerk/package_graph' - require 'visualize_packwerk/package_relationships' + sig { params(teams: T::Array[CodeTeams::Team]).void } + def self.team_graph!(teams) + PackageRelationships.new.create_team_graph!(teams) + end end diff --git a/lib/visualize_packwerk/railtie.rb b/lib/visualize_packwerk/railtie.rb deleted file mode 100644 index 2700fce..0000000 --- a/lib/visualize_packwerk/railtie.rb +++ /dev/null @@ -1,15 +0,0 @@ -# typed: ignore - -require 'visualize_packwerk' -require 'rails' - -module VisualizePackwerk - class Railtie < Rails::Railtie - railtie_name :visualize_packwerk - - rake_tasks do - path = File.expand_path(__dir__) - Dir.glob("#{path}/tasks/visualize_packwerk.rake").each { |f| load f } - end - end -end diff --git a/lib/visualize_packwerk/tasks/visualize_packwerk.rake b/lib/visualize_packwerk/tasks/visualize_packwerk.rake deleted file mode 100644 index 8c114a6..0000000 --- a/lib/visualize_packwerk/tasks/visualize_packwerk.rake +++ /dev/null @@ -1,73 +0,0 @@ -# typed: strict - -module VisualizePackwerk - class TaskLoader - include Rake::DSL - extend T::Sig - - sig { void } - def create_tasks! - namespace(:visualize_packwerk) do - # This creates the array of symbols that are needed to declare an argument to a rake task - package_args = (1..100).map { |i| "package#{i}".to_sym } - - desc('Graph packages') - task(:package_relationships, package_args => :environment) do |_task, args| - show_all_packs = args.to_hash.values.none? - packages = if show_all_packs - ParsePackwerk.all - else - args.to_hash.values.map do |pack_name| - found_package = ParsePackwerk.all.find { |p| p.name == pack_name } - if found_package.nil? - abort "Could not find pack with name: #{pack_name}" - end - - found_package - end - end - - PackageRelationships.new.create_package_graph!(packages) - end - - # This creates the array of symbols that are needed to declare an argument to a rake task - team_args = (1..5).map { |i| "team#{i}".to_sym } - - desc('Graph packages for teams') - task(:package_relationships_for_teams, team_args => :environment) do |_task, args| - teams = args.to_hash.values.map do |team_name| - team = CodeTeams.find(team_name) - if team.nil? - abort("Could not find team with name: #{team_name}. Check your config/teams/subdirectory/team.yml for correct team spelling, e.g. `Product Infrastructure`") - end - - team - end - - PackageRelationships.new.create_package_graph_for_teams!(teams) - end - - desc('Graph team relationships') - task(:team_relationships, team_args => :environment) do |_task, args| - show_all_teams = args.to_hash.values.none? - teams = if show_all_teams - CodeTeams.all - else - args.to_hash.values.map do |team_name| - team = CodeTeams.find(team_name) - if team.nil? - abort("Could not find team with name: #{team_name}. Check your config/teams/subdirectory/team.yml for correct team spelling, e.g. `Product Infrastructure`") - end - - team - end - end - - PackageRelationships.new.create_team_graph!(teams, show_all_teams: show_all_teams) - end - end - end - end -end - -VisualizePackwerk::TaskLoader.new.create_tasks! diff --git a/visualize_packwerk.gemspec b/visualize_packwerk.gemspec index 4436125..eaab0a9 100644 --- a/visualize_packwerk.gemspec +++ b/visualize_packwerk.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "visualize_packwerk" - spec.version = '0.0.5' + spec.version = '0.0.6' spec.authors = ['Gusto Engineers'] spec.email = ['dev@gusto.com'] spec.summary = 'A gem to visualize connections in a Rails app that uses Packwerk'