-
-
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.
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
- Loading branch information
1 parent
a40d457
commit 6c96ab8
Showing
5 changed files
with
129 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,43 @@ | ||
module Suspenders | ||
module Generators | ||
module Install | ||
class WebGenerator < Rails::Generators::Base | ||
include Suspenders::Generators::APIAppUnsupported | ||
include Suspenders::Generators::DatabaseUnsupported | ||
|
||
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:rake" | ||
generate "suspenders:setup" | ||
generate "suspenders:tasks" | ||
generate "suspenders:testing" | ||
generate "suspenders:views" | ||
|
||
# jobs needs to be invoked before styles, since the syles generator | ||
# creates Procfile.dev | ||
generate "suspenders:styles" | ||
generate "suspenders:jobs" | ||
|
||
# Run after styles, since that creates a package.json file | ||
generate "suspenders:lint" | ||
|
||
# Needs to be run last since it depends on lint, testing, and | ||
# advisories | ||
generate "suspenders:ci" | ||
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,31 @@ | ||
def apply_template! | ||
if options[:database] == "postgresql" && options[:skip_test] | ||
after_bundle do | ||
gem_group :development, :test do | ||
gem "suspenders", github: "thoughtbot/suspenders", branch: "suspenders-3-0-0-web-generator" | ||
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/suspenders-3-0-0-web-generator/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 |