Skip to content

Commit

Permalink
Introduce suspenders:prerequisites generator (#1171)
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]: https://github.com/rails/rails/blob/68b20b6513fe56ca80e4966628c231b4d6113bea/railties/lib/rails/generators/rails/app/app_generator.rb#L57-L59
[2]: https://github.com/rails/rails/blob/e8638c9a942e94f097dc8f37a3b58ac067a5ca16/railties/lib/rails/generators/app_base.rb#L18
[3]: rails/rails#51393
  • Loading branch information
stevepolitodesign authored Mar 22, 2024
1 parent 87d1f5a commit 52e99e9
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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 52e99e9

Please sign in to comment.