diff --git a/NEWS.md b/NEWS.md index 31563045d..7831295c6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Unreleased * Introduce `suspenders:db:migrate` task * Introduce `suspenders:email` generator * Introduce `suspenders:testing` generator +* Introduce `suspenders:prerequisites` generator 20230113.0 (January, 13, 2023) diff --git a/README.md b/README.md index f909dd25c..4876d7085 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,14 @@ Set up the project for an in-depth test-driven development workflow via [rspec-rails]: https://github.com/rspec/rspec-rails +#### Prerequisites + +Configures prerequisites. Currently Node. + +``` +bin/rails g suspenders:prerequisites +``` + ## Contributing See the [CONTRIBUTING] document. diff --git a/lib/generators/suspenders/prerequisites_generator.rb b/lib/generators/suspenders/prerequisites_generator.rb new file mode 100644 index 000000000..1063b4b8f --- /dev/null +++ b/lib/generators/suspenders/prerequisites_generator.rb @@ -0,0 +1,13 @@ +module Suspenders + module Generators + class PrerequisitesGenerator < Rails::Generators::Base + source_root File.expand_path("../../templates/prerequisites", __FILE__) + + desc "Configures prerequisites. Currently Node." + + def node_version + template "node-version", ".node-version" + end + end + end +end diff --git a/lib/generators/templates/prerequisites/node-version.tt b/lib/generators/templates/prerequisites/node-version.tt new file mode 100644 index 000000000..934c88064 --- /dev/null +++ b/lib/generators/templates/prerequisites/node-version.tt @@ -0,0 +1 @@ +<%= Suspenders::NODE_LTS_VERSION %> diff --git a/lib/suspenders/version.rb b/lib/suspenders/version.rb index 8f46d901c..bad1e5174 100644 --- a/lib/suspenders/version.rb +++ b/lib/suspenders/version.rb @@ -2,4 +2,5 @@ module Suspenders VERSION = "3.0.0".freeze RAILS_VERSION = "~> 7.0".freeze MINIMUM_RUBY_VERSION = ">= 3.1".freeze + NODE_LTS_VERSION = "20.11.1".freeze end diff --git a/test/generators/suspenders/prerequisites_generator_test.rb b/test/generators/suspenders/prerequisites_generator_test.rb new file mode 100644 index 000000000..c41536bbd --- /dev/null +++ b/test/generators/suspenders/prerequisites_generator_test.rb @@ -0,0 +1,32 @@ +require "test_helper" +require "generators/suspenders/prerequisites_generator" + +module Suspenders + module Generators + class PrerequisitesGeneratorTest < Rails::Generators::TestCase + include Suspenders::TestHelpers + + tests Suspenders::Generators::PrerequisitesGenerator + destination Rails.root + teardown :restore_destination + + test "generates .node-version file" do + run_generator + + assert_file app_root(".node-version") do |file| + assert_match(/20\.11\.1/, file) + end + end + + test "has custom description" do + assert_no_match(/Description/, generator.class.desc) + end + + private + + def restore_destination + remove_file_if_exists ".node-version" + end + end + end +end diff --git a/test/suspenders_test.rb b/test/suspenders_test.rb index 948ef5022..cf14b1478 100644 --- a/test/suspenders_test.rb +++ b/test/suspenders_test.rb @@ -12,4 +12,8 @@ class SuspendersTest < ActiveSupport::TestCase test "it has a Minimum Ruby version number" do assert Suspenders::MINIMUM_RUBY_VERSION end + + test "it has a Node LTS version number" do + assert Suspenders::NODE_LTS_VERSION + end end