- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Introduce
suspenders:install:web
generator and application template
Create generator to invoke all necessary generators. We add it to the `install` namespace to provide flexibility should we add other installation options, such as ones for API Only applications. Introduces [template][] as a means to invoke `suspenders:install:web` when creating a new application. This serves as an alternative to the system executable that was removed. We call `db:prepare` in the template to ensure `bin/setup` works as expected. This is because we overrode that file to use `dev:prime`, which assume the database has been created. [template]: https://guides.rubyonrails.org/rails_application_templates.html
1 parent
c694b2a
commit c7accb4
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Suspenders | ||
module Generators | ||
module Install | ||
class WebGenerator < Rails::Generators::Base | ||
include Suspenders::Generators::APIAppUnsupported | ||
include Suspenders::Generators::DatabaseUnsupported | ||
|
||
desc <<~MARKDOWN | ||
Invokes all necessary generators for new Rails applications generated with Suspenders. | ||
This generatator is intended to be invoked as part of an [application template][]. | ||
``` | ||
rails new suspenders_qa \ | ||
--skip-test \ | ||
-d=postgresql \ | ||
-m=https://raw.githubusercontent.com/thoughtbot/suspenders/main/lib/install/web.rb | ||
``` | ||
[application template]: https://guides.rubyonrails.org/rails_application_templates.html | ||
MARKDOWN | ||
|
||
def invoke_generators | ||
# This needs to go first, since it configures `.node-version` | ||
generate "suspenders:prerequisites" | ||
|
||
generate "suspenders:accessibility" | ||
generate "suspenders:advisories" | ||
generate "suspenders:email" | ||
generate "suspenders:factories" | ||
generate "suspenders:inline_svg" | ||
generate "suspenders:lint" | ||
generate "suspenders:rake" | ||
generate "suspenders:setup" | ||
generate "suspenders:tasks" | ||
generate "suspenders:testing" | ||
generate "suspenders:views" | ||
|
||
# suspenders:jobs needs to be invoked before suspenders:styles, since | ||
# suspenders:styles generator creates Procfile.dev | ||
generate "suspenders:styles" | ||
generate "suspenders:jobs" | ||
|
||
# Needs to run after other generators, since some touch the | ||
# configuration files. | ||
generate "suspenders:environments:test" | ||
generate "suspenders:environments:development" | ||
generate "suspenders:environments:production" | ||
|
||
# Needs to be run last since it depends on lint, testing, and | ||
# advisories | ||
generate "suspenders:ci" | ||
end | ||
|
||
def cleanup | ||
rake "suspenders:cleanup:organize_gemfile" | ||
rake "suspenders:cleanup:generate_readme" | ||
end | ||
|
||
def lint | ||
run "yarn run fix:prettier" | ||
run "bundle exec rake standard:fix_unsafely" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def apply_template! | ||
if options[:database] == "postgresql" && options[:skip_test] | ||
after_bundle do | ||
gem_group :development, :test do | ||
# TODO: Update once in `main` | ||
gem "suspenders", github: "thoughtbot/suspenders", branch: "suspenders-3-0-0" | ||
end | ||
|
||
run "bundle install" | ||
|
||
generate "suspenders:install:web" | ||
rails_command "db:prepare" | ||
|
||
say "\nCongratulations! You just pulled our suspenders." | ||
end | ||
else | ||
message = <<~ERROR | ||
=== Please use the correct options === | ||
rails new <app_name> \\ | ||
--skip-test \\ | ||
-d=postgresql \\ | ||
-m=https://raw.githubusercontent.com/thoughtbot/suspenders/main/lib/install/web.rb | ||
ERROR | ||
|
||
fail Rails::Generators::Error, message | ||
end | ||
end | ||
|
||
apply_template! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "test_helper" | ||
require "generators/suspenders/install/web_generator" | ||
|
||
module Suspenders | ||
module Generators | ||
module Install | ||
class WebGeneratorTest < Rails::Generators::TestCase | ||
include Suspenders::TestHelpers | ||
|
||
tests Suspenders::Generators::Install::WebGenerator | ||
destination Rails.root | ||
setup :prepare_destination | ||
teardown :restore_destination | ||
|
||
test "raises if API only application" do | ||
within_api_only_app do | ||
assert_raises Suspenders::Generators::APIAppUnsupported::Error do | ||
run_generator | ||
end | ||
end | ||
end | ||
|
||
test "raises if PostgreSQL is not the adapter" do | ||
with_database "unsupported" do | ||
assert_raises Suspenders::Generators::DatabaseUnsupported::Error do | ||
run_generator | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def prepare_destination | ||
touch "Gemfile" | ||
end | ||
|
||
def restore_destination | ||
remove_file_if_exists "Gemfile" | ||
end | ||
end | ||
end | ||
end | ||
end |