diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d974882..9e15843 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,15 +51,3 @@ jobs: ruby-version: head - name: Run style checks run: bundle exec rubocop - documentation: - runs-on: ubuntu-latest - name: CLI Documentation - steps: - - uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445 - - name: Set up Ruby - uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 - with: - bundler-cache: true - ruby-version: head - - name: Check autogenerated documentation - run: ruby docs/verify_docs.rb diff --git a/Gemfile.lock b/Gemfile.lock index c68344c..39a2cd3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,12 +17,12 @@ GIT PATH remote: . specs: - packs (0.0.24) + packs (0.0.25) code_ownership (>= 1.33.0) - colorize packs-specification packwerk parse_packwerk + rainbow rubocop-packs sorbet-runtime thor @@ -61,7 +61,6 @@ GEM code_teams (1.0.2) sorbet-runtime coderay (1.1.3) - colorize (1.1.0) concurrent-ruby (1.2.2) constant_resolver (0.2.0) crass (1.0.6) @@ -81,10 +80,10 @@ GEM nokogiri (1.15.3) mini_portile2 (~> 2.8.2) racc (~> 1.4) - packs-specification (0.0.9) + packs-specification (0.0.10) sorbet-runtime parallel (1.23.0) - parse_packwerk (0.19.3) + parse_packwerk (0.20.0) sorbet-runtime parser (3.2.2.3) ast (~> 2.4.1) @@ -145,21 +144,19 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.23.1) rubocop (~> 1.33) - rubocop-packs (0.0.42) + rubocop-packs (0.0.43) activesupport packs-specification parse_packwerk - rubocop + rubocop (~> 1.0) rubocop-sorbet sorbet-runtime rubocop-rspec (2.23.2) rubocop (~> 1.33) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) - rubocop-sorbet (0.7.2) + rubocop-sorbet (0.7.3) rubocop (>= 0.90.0) - ruby-graphviz (1.2.5) - rexml ruby-progressbar (1.13.0) smart_properties (1.17.0) sorbet (0.5.10957) @@ -208,12 +205,9 @@ GEM unparser (0.6.8) diff-lcs (~> 1.3) parser (>= 3.2.0) - visualize_packs (0.3.1) - code_ownership + visualize_packs (0.5.3) packs-specification - parse_packwerk - rake - ruby-graphviz + parse_packwerk (>= 0.20.0) sorbet-runtime wisper (2.0.1) yard (0.9.34) diff --git a/docs/verify_docs.rb b/docs/verify_docs.rb deleted file mode 100644 index 9c205e6..0000000 --- a/docs/verify_docs.rb +++ /dev/null @@ -1,41 +0,0 @@ -# typed: strict - -require 'bundler/inline' - -# Send is to ward off Sorbet which can't type this method invocation -send(:gemfile) do - send(:source, 'https://rubygems.org') - gem 'packs', path: '../' -end - -all_docs = [] -Packs::CLI.all_commands.each do |_command_name, command| - all_docs << <<~DOCUMENTATION - ## #{command.description} - `bin/packs #{command.usage}` - - DOCUMENTATION - - if command.long_description - all_docs << command.long_description - all_docs << "\n" - end -end - -new_autogenerated_content = <<~MARKDOWN.chomp - ## CLI Documentation - #{all_docs.join} - ## Releasing -MARKDOWN - -readme = Pathname.new('README.md') -new_content = readme.read.gsub(/## CLI Documentation.*?## Releasing/m, new_autogenerated_content) - -if ENV['OVERWRITE'] - readme.write(new_content) -elsif readme.read == new_content - exit 0 -else - puts 'README.md is out of date. Use OVERWRITE=1 ruby docs/verify_docs.rb' - exit 1 -end diff --git a/lib/packs.rb b/lib/packs.rb index 2de84b5..154b686 100644 --- a/lib/packs.rb +++ b/lib/packs.rb @@ -4,7 +4,7 @@ require 'fileutils' # External gem requires -require 'colorized_string' +require 'rainbow' # Internal gem requires require 'packs-specification' diff --git a/lib/packs/logging.rb b/lib/packs/logging.rb index 5b8b526..15be4d1 100644 --- a/lib/packs/logging.rb +++ b/lib/packs/logging.rb @@ -1,6 +1,6 @@ # typed: strict -require 'colorized_string' +require 'rainbow' module Packs module Logging @@ -9,14 +9,14 @@ module Logging sig { params(title: String, block: T.proc.void).void } def self.section(title, &block) print_divider - out ColorizedString.new(title).green.bold + out Rainbow(title).green.bold out "\n" yield end sig { params(text: String).void } def self.print_bold_green(text) - out ColorizedString.new(text).green.bold + out Rainbow(text).green.bold end sig { params(text: String).void } diff --git a/lib/packs/private.rb b/lib/packs/private.rb index 49ebefa..919b3f0 100644 --- a/lib/packs/private.rb +++ b/lib/packs/private.rb @@ -2,7 +2,7 @@ require 'pathname' require 'fileutils' -require 'colorized_string' +require 'rainbow' require 'sorbet-runtime' require 'packs/private/file_move_operation' @@ -313,7 +313,7 @@ def self.package_filepath(file_move_operation, per_file_processors) sig { params(origin: Pathname, destination: Pathname).void } def self.idempotent_mv(origin, destination) if origin.exist? && destination.exist? - Logging.print ColorizedString.new("[SKIP] Not moving #{origin}, #{destination} already exists").red + Logging.print Rainbow("[SKIP] Not moving #{origin}, #{destination} already exists").red elsif origin.exist? && !destination.exist? destination.dirname.mkpath @@ -321,11 +321,11 @@ def self.idempotent_mv(origin, destination) # use git mv so that git knows that it was a move FileUtils.mv(origin, destination) elsif !origin.exist? && destination.exist? - Logging.print ColorizedString.new("[SKIP] Not moving #{origin}, does not exist, (#{destination} already exists)").red + Logging.print Rainbow("[SKIP] Not moving #{origin}, does not exist, (#{destination} already exists)").red else # We could choose to print this in a `--verbose` mode. For now, we find that printing this text in red confuses folks more than it informs them. # This is because it's perfectly common for a spec to not exist for a file, so at best it's a warning. - # Logging.print ColorizedString.new("[SKIP] Not moving #{origin}, does not exist").red + # Logging.print Rainbow("[SKIP] Not moving #{origin}, does not exist").red end end diff --git a/packs.gemspec b/packs.gemspec index 6708d21..86c19cd 100644 --- a/packs.gemspec +++ b/packs.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'packs' - spec.version = '0.0.24' + spec.version = '0.0.25' spec.authors = ['Gusto Engineers'] spec.email = ['dev@gusto.com'] @@ -29,10 +29,10 @@ Gem::Specification.new do |spec| spec.executables = %w[packs] spec.add_dependency 'code_ownership', '>= 1.33.0' - spec.add_dependency 'colorize' spec.add_dependency 'packs-specification' spec.add_dependency 'packwerk' spec.add_dependency 'parse_packwerk' + spec.add_dependency 'rainbow' spec.add_dependency 'rubocop-packs' spec.add_dependency 'sorbet-runtime' spec.add_dependency 'thor' diff --git a/sorbet/rbi/gems/colorize@0.8.1.rbi b/sorbet/rbi/gems/colorize@0.8.1.rbi deleted file mode 100644 index ef5d54e..0000000 --- a/sorbet/rbi/gems/colorize@0.8.1.rbi +++ /dev/null @@ -1,84 +0,0 @@ -# DO NOT EDIT MANUALLY -# This is an autogenerated file for types exported from the `colorize` gem. -# Please instead update this file by running `bin/tapioca gem colorize`. - -# typed: true - -module Colorize; end - -module Colorize::ClassMethods - def color_codes; end - def color_matrix(_ = T.unsafe(nil)); end - def color_methods; end - def color_samples; end - def colors; end - def disable_colorization(value = T.unsafe(nil)); end - def disable_colorization=(value); end - def mode_codes; end - def modes; end - def modes_methods; end -end - -module Colorize::InstanceMethods - def colorize(params); end - def colorized?; end - def uncolorize; end - - private - - def background_color(color); end - def color(color); end - def color_from_symbol(match, symbol); end - def colors_from_hash(match, hash); end - def colors_from_params(match, params); end - def defaults_colors(match); end - def mode(mode); end - def require_windows_libs; end - def scan_for_colors; end - def split_colors(match); end -end - -class ColorizedString < ::String - def black; end - def blink; end - def blue; end - def bold; end - def cyan; end - def green; end - def hide; end - def italic; end - def light_black; end - def light_blue; end - def light_cyan; end - def light_green; end - def light_magenta; end - def light_red; end - def light_white; end - def light_yellow; end - def magenta; end - def on_black; end - def on_blue; end - def on_cyan; end - def on_green; end - def on_light_black; end - def on_light_blue; end - def on_light_cyan; end - def on_light_green; end - def on_light_magenta; end - def on_light_red; end - def on_light_white; end - def on_light_yellow; end - def on_magenta; end - def on_red; end - def on_white; end - def on_yellow; end - def red; end - def swap; end - def underline; end - def white; end - def yellow; end - - class << self - def [](string); end - end -end diff --git a/sorbet/rbi/gems/rainbow@3.1.1.rbi b/sorbet/rbi/gems/rainbow@3.1.1.rbi index e704587..a1a4eb4 100644 --- a/sorbet/rbi/gems/rainbow@3.1.1.rbi +++ b/sorbet/rbi/gems/rainbow@3.1.1.rbi @@ -4,154 +4,401 @@ # This is an autogenerated file for types exported from the `rainbow` gem. # Please instead update this file by running `bin/tapioca gem rainbow`. +class Object < ::BasicObject + include ::Kernel + include ::ActiveSupport::ForkTracker::CoreExt + include ::ActiveSupport::ForkTracker::CoreExtPrivate + include ::PP::ObjectMixin + + private + + # source://rainbow//lib/rainbow/global.rb#23 + def Rainbow(string); end +end + +# source://rainbow//lib/rainbow/string_utils.rb#3 module Rainbow class << self + # source://rainbow//lib/rainbow/global.rb#10 def enabled; end + + # source://rainbow//lib/rainbow/global.rb#14 def enabled=(value); end + + # source://rainbow//lib/rainbow/global.rb#6 def global; end + + # source://rainbow//lib/rainbow.rb#6 def new; end + + # source://rainbow//lib/rainbow/global.rb#18 def uncolor(string); end end end +# source://rainbow//lib/rainbow/color.rb#4 class Rainbow::Color + # Returns the value of attribute ground. + # + # source://rainbow//lib/rainbow/color.rb#5 def ground; end class << self + # source://rainbow//lib/rainbow/color.rb#7 def build(ground, values); end + + # source://rainbow//lib/rainbow/color.rb#40 def parse_hex_color(hex); end end end +# source://rainbow//lib/rainbow/color.rb#54 class Rainbow::Color::Indexed < ::Rainbow::Color + # @return [Indexed] a new instance of Indexed + # + # source://rainbow//lib/rainbow/color.rb#57 def initialize(ground, num); end + # source://rainbow//lib/rainbow/color.rb#62 def codes; end + + # Returns the value of attribute num. + # + # source://rainbow//lib/rainbow/color.rb#55 def num; end end +# source://rainbow//lib/rainbow/color.rb#69 class Rainbow::Color::Named < ::Rainbow::Color::Indexed + # @return [Named] a new instance of Named + # + # source://rainbow//lib/rainbow/color.rb#90 def initialize(ground, name); end class << self + # source://rainbow//lib/rainbow/color.rb#82 def color_names; end + + # source://rainbow//lib/rainbow/color.rb#86 def valid_names; end end end +# source://rainbow//lib/rainbow/color.rb#70 Rainbow::Color::Named::NAMES = T.let(T.unsafe(nil), Hash) +# source://rainbow//lib/rainbow/color.rb#100 class Rainbow::Color::RGB < ::Rainbow::Color::Indexed + # @return [RGB] a new instance of RGB + # + # source://rainbow//lib/rainbow/color.rb#107 def initialize(ground, *values); end + # Returns the value of attribute b. + # + # source://rainbow//lib/rainbow/color.rb#101 def b; end + + # source://rainbow//lib/rainbow/color.rb#116 def codes; end + + # Returns the value of attribute g. + # + # source://rainbow//lib/rainbow/color.rb#101 def g; end + + # Returns the value of attribute r. + # + # source://rainbow//lib/rainbow/color.rb#101 def r; end private + # source://rainbow//lib/rainbow/color.rb#122 def code_from_rgb; end class << self + # source://rainbow//lib/rainbow/color.rb#103 def to_ansi_domain(value); end end end +# source://rainbow//lib/rainbow/color.rb#129 class Rainbow::Color::X11Named < ::Rainbow::Color::RGB include ::Rainbow::X11ColorNames + # @return [X11Named] a new instance of X11Named + # + # source://rainbow//lib/rainbow/color.rb#140 def initialize(ground, name); end class << self + # source://rainbow//lib/rainbow/color.rb#132 def color_names; end + + # source://rainbow//lib/rainbow/color.rb#136 def valid_names; end end end +# source://rainbow//lib/rainbow/null_presenter.rb#4 class Rainbow::NullPresenter < ::String + # source://rainbow//lib/rainbow/null_presenter.rb#9 def background(*_values); end + + # source://rainbow//lib/rainbow/null_presenter.rb#9 def bg(*_values); end + + # source://rainbow//lib/rainbow/null_presenter.rb#49 def black; end + + # source://rainbow//lib/rainbow/null_presenter.rb#33 def blink; end + + # source://rainbow//lib/rainbow/null_presenter.rb#65 def blue; end + + # source://rainbow//lib/rainbow/null_presenter.rb#17 def bold; end + + # source://rainbow//lib/rainbow/null_presenter.rb#17 def bright; end + + # source://rainbow//lib/rainbow/null_presenter.rb#5 def color(*_values); end + + # source://rainbow//lib/rainbow/null_presenter.rb#45 def cross_out; end + + # source://rainbow//lib/rainbow/null_presenter.rb#73 def cyan; end + + # source://rainbow//lib/rainbow/null_presenter.rb#21 def dark; end + + # source://rainbow//lib/rainbow/null_presenter.rb#21 def faint; end + + # source://rainbow//lib/rainbow/null_presenter.rb#5 def fg(*_values); end + + # source://rainbow//lib/rainbow/null_presenter.rb#5 def foreground(*_values); end + + # source://rainbow//lib/rainbow/null_presenter.rb#57 def green; end + + # source://rainbow//lib/rainbow/null_presenter.rb#41 def hide; end + + # source://rainbow//lib/rainbow/null_presenter.rb#37 def inverse; end + + # source://rainbow//lib/rainbow/null_presenter.rb#25 def italic; end + + # source://rainbow//lib/rainbow/null_presenter.rb#69 def magenta; end + + # source://rainbow//lib/rainbow/null_presenter.rb#81 def method_missing(method_name, *args); end + + # source://rainbow//lib/rainbow/null_presenter.rb#53 def red; end + + # source://rainbow//lib/rainbow/null_presenter.rb#13 def reset; end + + # source://rainbow//lib/rainbow/null_presenter.rb#45 def strike; end + + # source://rainbow//lib/rainbow/null_presenter.rb#29 def underline; end + + # source://rainbow//lib/rainbow/null_presenter.rb#77 def white; end + + # source://rainbow//lib/rainbow/null_presenter.rb#61 def yellow; end private + # @return [Boolean] + # + # source://rainbow//lib/rainbow/null_presenter.rb#89 def respond_to_missing?(method_name, *args); end end +# source://rainbow//lib/rainbow/presenter.rb#8 class Rainbow::Presenter < ::String + # Sets background color of this text. + # + # source://rainbow//lib/rainbow/presenter.rb#30 def background(*values); end + + # Sets background color of this text. + # + # source://rainbow//lib/rainbow/presenter.rb#30 def bg(*values); end + + # source://rainbow//lib/rainbow/presenter.rb#92 def black; end + + # Turns on blinking attribute for this text (not well supported by terminal + # emulators). + # + # source://rainbow//lib/rainbow/presenter.rb#72 def blink; end + + # source://rainbow//lib/rainbow/presenter.rb#108 def blue; end + + # Turns on bright/bold for this text. + # + # source://rainbow//lib/rainbow/presenter.rb#45 def bold; end + + # Turns on bright/bold for this text. + # + # source://rainbow//lib/rainbow/presenter.rb#45 def bright; end + + # Sets color of this text. + # + # source://rainbow//lib/rainbow/presenter.rb#22 def color(*values); end + + # source://rainbow//lib/rainbow/presenter.rb#86 def cross_out; end + + # source://rainbow//lib/rainbow/presenter.rb#116 def cyan; end + + # Turns on faint/dark for this text (not well supported by terminal + # emulators). + # + # source://rainbow//lib/rainbow/presenter.rb#53 def dark; end + + # Turns on faint/dark for this text (not well supported by terminal + # emulators). + # + # source://rainbow//lib/rainbow/presenter.rb#53 def faint; end + + # Sets color of this text. + # + # source://rainbow//lib/rainbow/presenter.rb#22 def fg(*values); end + + # Sets color of this text. + # + # source://rainbow//lib/rainbow/presenter.rb#22 def foreground(*values); end + + # source://rainbow//lib/rainbow/presenter.rb#100 def green; end + + # Hides this text (set its color to the same as background). + # + # source://rainbow//lib/rainbow/presenter.rb#82 def hide; end + + # Inverses current foreground/background colors. + # + # source://rainbow//lib/rainbow/presenter.rb#77 def inverse; end + + # Turns on italic style for this text (not well supported by terminal + # emulators). + # + # source://rainbow//lib/rainbow/presenter.rb#61 def italic; end + + # source://rainbow//lib/rainbow/presenter.rb#112 def magenta; end + + # We take care of X11 color method call here. + # Such as #aqua, #ghostwhite. + # + # source://rainbow//lib/rainbow/presenter.rb#126 def method_missing(method_name, *args); end + + # source://rainbow//lib/rainbow/presenter.rb#96 def red; end + + # Resets terminal to default colors/backgrounds. + # + # It shouldn't be needed to use this method because all methods + # append terminal reset code to end of string. + # + # source://rainbow//lib/rainbow/presenter.rb#40 def reset; end + + # source://rainbow//lib/rainbow/presenter.rb#86 def strike; end + + # Turns on underline decoration for this text. + # + # source://rainbow//lib/rainbow/presenter.rb#66 def underline; end + + # source://rainbow//lib/rainbow/presenter.rb#120 def white; end + + # source://rainbow//lib/rainbow/presenter.rb#104 def yellow; end private + # @return [Boolean] + # + # source://rainbow//lib/rainbow/presenter.rb#134 def respond_to_missing?(method_name, *args); end + + # source://rainbow//lib/rainbow/presenter.rb#140 def wrap_with_sgr(codes); end end +# source://rainbow//lib/rainbow/presenter.rb#9 Rainbow::Presenter::TERM_EFFECTS = T.let(T.unsafe(nil), Hash) +# source://rainbow//lib/rainbow/string_utils.rb#4 class Rainbow::StringUtils class << self + # source://rainbow//lib/rainbow/string_utils.rb#17 def uncolor(string); end + + # source://rainbow//lib/rainbow/string_utils.rb#5 def wrap_with_sgr(string, codes); end end end +# source://rainbow//lib/rainbow/wrapper.rb#7 class Rainbow::Wrapper + # @return [Wrapper] a new instance of Wrapper + # + # source://rainbow//lib/rainbow/wrapper.rb#10 def initialize(enabled = T.unsafe(nil)); end + # Returns the value of attribute enabled. + # + # source://rainbow//lib/rainbow/wrapper.rb#8 def enabled; end + + # Sets the attribute enabled + # + # @param value the value to set the attribute enabled to. + # + # source://rainbow//lib/rainbow/wrapper.rb#8 def enabled=(_arg0); end + + # source://rainbow//lib/rainbow/wrapper.rb#14 def wrap(string); end end +# source://rainbow//lib/rainbow/x11_color_names.rb#4 module Rainbow::X11ColorNames; end + +# source://rainbow//lib/rainbow/x11_color_names.rb#5 Rainbow::X11ColorNames::NAMES = T.let(T.unsafe(nil), Hash) diff --git a/spec/packs_spec.rb b/spec/packs_spec.rb index 79568a6..7c0e2fe 100644 --- a/spec/packs_spec.rb +++ b/spec/packs_spec.rb @@ -1095,12 +1095,12 @@ def write_codeownership_config logged_output = '' expect(Packs::Logging).to receive(:out).at_least(:once) do |string| - logged_output += ColorizedString.new(string).uncolorize + logged_output += Rainbow.uncolor(string) logged_output += "\n" end expect(Packs::Logging).to receive(:print).at_least(:once) do |string| - logged_output += ColorizedString.new(string).uncolorize + logged_output += Rainbow.uncolor(string) logged_output += "\n" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5e4f2c3..f99b58a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,8 @@ # frozen_string_literal: true require 'packs' +# This require should eventually be done in packs/rspec/support, since it's needed to load the Dir.mktmpdir method +require 'tmpdir' require 'packs/rspec/support' RSpec.configure do |config| diff --git a/spec/verify_docs_spec.rb b/spec/verify_docs_spec.rb new file mode 100644 index 0000000..e9172c7 --- /dev/null +++ b/spec/verify_docs_spec.rb @@ -0,0 +1,44 @@ +# typed: false + +RSpec.describe Packs, :skip_chdir_to_tmpdir do + let(:readme) do + Pathname.new('README.md') + end + + let(:actual_content) { readme.read } + + let(:expected_content) do + all_docs = [] + Packs::CLI.all_commands.each do |_command_name, command| + all_docs << <<~DOCUMENTATION + ## #{command.description} + `bin/packs #{command.usage}` + + DOCUMENTATION + + if command.long_description + all_docs << command.long_description + all_docs << "\n" + end + end + + new_autogenerated_content = <<~MARKDOWN.chomp + ## CLI Documentation + #{all_docs.join} + ## Releasing + MARKDOWN + new_content = readme.read.gsub(/## CLI Documentation.*?## Releasing/m, new_autogenerated_content) + + new_content + end + + describe 'CLI Documentation' do + it 'is up to date' do + if ENV['OVERWRITE'] + readme.write(expected_content) + else + expect(actual_content).to eq(expected_content), 'README.md is out of date. Use OVERWRITE=1 bundle exec rspec' + end + end + end +end