thoughtbot / suspenders

A Rails template with our standard defaults.
https://thoughtbot.com
MIT License
4.02k stars 528 forks source link

Introduce `suspenders:rake` generator #1144

Closed stevepolitodesign closed 11 months ago

stevepolitodesign commented 1 year ago

Add necessary files to make the plugin an engine, which automatically loads Rake tasks located in lib/tasks. This means when the suspenders gem is installed, the consumer can run bundle exec rake suspenders:rake, and any future tasks.

Because suspenders:lint and suspenders:advisories may not necessarily have been invoked, we need to check if those gems are installed.

How to review this pull request

  1. Spin up a new Rails application.

    rails new rake_demo
  2. Scaffold a domain in order to generate passing tests.

    bin/rails g scaffold post title
    bin/rails db:migrate
  3. Install suspenders on this branch.

    group :development, :test do
      gem "suspenders", github: "thoughtbot/suspenders", branch: "suspenders-3-0-0-rake-generator"
    end
  4. Run the following generators.

    bin/rails g suspenders:advisories
    bin/rails g suspenders:lint
    bin/rails g suspenders:rake
  5. Run Rake and note the output. It should run the test suite, run standard and run bundler-audit.

    bundle exec rake

Co-authored-by: Mike Burns mburns@thoughtbot.com

mike-burns commented 1 year ago

I think we're running into a flexibility issue.

What if we made a default rake task that looks for whether bundler-audit is installed and run it if so, ignore it otherwise? I have no idea whether that's possible, but it would allow for the kind of extensibility we need.

in lib/suspenders/tasks.rb

task :suspenders do
  if Bundler.rubygems.find_name("bundle-audit").any?
    Rake::Task[:"bundle:audit"].run
  end

  if Bundler.rubygems.find_name("standard").any?
    Rake::Task[:standard].run
  end
end

generated Rakefile

require 'suspenders/tasks'
default: [:suspenders]