Skip to content

Commit e22a860

Browse files
Introduce suspenders:prerequisites generator
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
1 parent 87d1f5a commit e22a860

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Unreleased
1515
* Introduce `suspenders:db:migrate` task
1616
* Introduce `suspenders:email` generator
1717
* Introduce `suspenders:testing` generator
18+
* Introduce `suspenders:prerequisites` generator
1819

1920
20230113.0 (January, 13, 2023)
2021

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ Set up the project for an in-depth test-driven development workflow via
180180

181181
[rspec-rails]: https://github.com/rspec/rspec-rails
182182

183+
#### Prerequisites
184+
185+
Configures prerequisites. Currently Node.
186+
187+
```
188+
bin/rails g suspenders:prerequisites
189+
```
190+
183191
## Contributing
184192

185193
See the [CONTRIBUTING] document.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Suspenders
2+
module Generators
3+
class PrerequisitesGenerator < Rails::Generators::Base
4+
source_root File.expand_path("../../templates/prerequisites", __FILE__)
5+
6+
desc "Configures prerequisites. Currently Node."
7+
8+
def node_version
9+
template "node-version", ".node-version"
10+
end
11+
end
12+
end
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= Suspenders::NODE_LTS_VERSION %>

lib/suspenders/version.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ module Suspenders
22
VERSION = "3.0.0".freeze
33
RAILS_VERSION = "~> 7.0".freeze
44
MINIMUM_RUBY_VERSION = ">= 3.1".freeze
5+
NODE_LTS_VERSION = "20.11.1".freeze
56
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "test_helper"
2+
require "generators/suspenders/prerequisites_generator"
3+
4+
module Suspenders
5+
module Generators
6+
class PrerequisitesGeneratorTest < Rails::Generators::TestCase
7+
include Suspenders::TestHelpers
8+
9+
tests Suspenders::Generators::PrerequisitesGenerator
10+
destination Rails.root
11+
teardown :restore_destination
12+
13+
test "generates .node-version file" do
14+
run_generator
15+
16+
assert_file app_root(".node-version") do |file|
17+
assert_match(/20\.11\.1/, file)
18+
end
19+
end
20+
21+
test "has custom description" do
22+
assert_no_match(/Description/, generator.class.desc)
23+
end
24+
25+
private
26+
27+
def restore_destination
28+
remove_file_if_exists ".node-version"
29+
end
30+
end
31+
end
32+
end

test/suspenders_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ class SuspendersTest < ActiveSupport::TestCase
1212
test "it has a Minimum Ruby version number" do
1313
assert Suspenders::MINIMUM_RUBY_VERSION
1414
end
15+
16+
test "it has a Node LTS version number" do
17+
assert Suspenders::NODE_LTS_VERSION
18+
end
1519
end

0 commit comments

Comments
 (0)