Skip to content

Commit

Permalink
Introduce suspenders:prerequisites generator
Browse files Browse the repository at this point in the history
Follow-up to #1148 and #1145

In #1148 and #1145, we introduce the need for yarn to manage
dependencies. Those commits failed to establish a `.node-version` file,
which [normally would be generated][1] by Rails if **not** using
`import-maps`.

This commit introduces that file, which compliments the existing
`.ruby-version` file that is generated.

I chose to use `.node-version` and not `.nvm` or `.tool-versions` to
keep parity with Rails.

The [current version][2] set by Rails is `18.15.0`, but a [future
commit][3] aims to use the latest LTS value. This commit aims to use
that version.

This commit will also benefit a future `suspenders:ci` generator, since
the `.node-version` file will be used in CI.

[1]: rails/rails#51393
[2]: https://github.com/rails/rails/blob/e8638c9a942e94f097dc8f37a3b58ac067a5ca16/railties/lib/rails/generators/app_base.rb#L18
[3]: rails/rails#51393
  • Loading branch information
stevepolitodesign committed Mar 22, 2024
1 parent 87d1f5a commit 6010f1e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/generators/suspenders/prerequisites_generator.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/generators/templates/prerequisites/node-version.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= Suspenders::NODE_LTS_VERSION %>
1 change: 1 addition & 0 deletions lib/suspenders/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions test/generators/suspenders/prerequisites_generator_test.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/suspenders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6010f1e

Please sign in to comment.