lib/rails/generators/app_base.rb in railties-7.0.0.alpha2 vs lib/rails/generators/app_base.rb in railties-7.0.0.rc1
- old
+ new
@@ -56,13 +56,15 @@
desc: "Skip Active Storage files"
class_option :skip_action_cable, type: :boolean, aliases: "-C", default: false,
desc: "Skip Action Cable files"
- class_option :skip_sprockets, type: :boolean, aliases: "-S", default: false,
- desc: "Skip Sprockets files"
+ class_option :skip_asset_pipeline, type: :boolean, aliases: "-A", default: false
+ class_option :asset_pipeline, type: :string, aliases: "-a", default: "sprockets",
+ desc: "Choose your asset pipeline [options: sprockets (default), propshaft]"
+
class_option :skip_javascript, type: :boolean, aliases: "-J", default: name == "plugin",
desc: "Skip JavaScript files"
class_option :skip_hotwire, type: :boolean, default: false,
desc: "Skip Hotwire integration"
@@ -104,10 +106,11 @@
end
private
def gemfile_entries # :doc:
[rails_gemfile_entry,
+ asset_pipeline_gemfile_entry,
database_gemfile_entry,
web_server_gemfile_entry,
javascript_gemfile_entry,
hotwire_gemfile_entry,
css_gemfile_entry,
@@ -146,11 +149,11 @@
self.rails_template = \
case options[:template]
when /^https?:\/\//
options[:template]
when String
- File.expand_path(options[:template], Dir.pwd)
+ File.expand_path(`echo #{options[:template]}`.strip)
else
options[:template]
end
end
@@ -163,17 +166,29 @@
def web_server_gemfile_entry # :doc:
GemfileEntry.new "puma", "~> 5.0", "Use the Puma web server [https://github.com/puma/puma]"
end
+ def asset_pipeline_gemfile_entry
+ return [] if options[:skip_asset_pipeline]
+
+ if options[:asset_pipeline] == "sprockets"
+ GemfileEntry.version "sprockets-rails", ">= 3.4.1",
+ "The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]"
+ elsif options[:asset_pipeline] == "propshaft"
+ GemfileEntry.version "propshaft", ">= 0.4.1", "The modern asset pipeline for Rails [https://github.com/rails/propshaft/]"
+ else
+ []
+ end
+ end
+
def include_all_railties? # :doc:
[
options.values_at(
:skip_active_record,
:skip_action_mailer,
:skip_test,
- :skip_sprockets,
:skip_action_cable,
:skip_active_job
),
skip_active_storage?,
skip_action_mailbox?,
@@ -216,10 +231,15 @@
def skip_dev_gems? # :doc:
options[:skip_dev_gems]
end
+ def skip_sprockets?
+ options[:skip_asset_pipeline] || options[:asset_pipeline] != "sprockets"
+ end
+
+
class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
def initialize(name, version, comment, options = {}, commented_out = false)
super
end
@@ -285,46 +305,56 @@
end
def jbuilder_gemfile_entry
return [] if options[:skip_jbuilder]
comment = "Build JSON APIs with ease [https://github.com/rails/jbuilder]"
- GemfileEntry.new "jbuilder", "~> 2.7", comment, {}, options[:api]
+ GemfileEntry.new "jbuilder", "~> 2.11", comment, {}, options[:api]
end
def javascript_gemfile_entry
return [] if options[:skip_javascript]
- if options[:javascript] == "importmap"
- GemfileEntry.version("importmap-rails", ">= 0.3.4", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]")
+ if adjusted_javascript_option == "importmap"
+ GemfileEntry.version("importmap-rails", ">= 0.9.2", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]")
else
- GemfileEntry.version "jsbundling-rails", "~> 0.1.0", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]"
+ GemfileEntry.version "jsbundling-rails", ">= 0.2.2", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]"
end
end
def hotwire_gemfile_entry
return [] if options[:skip_javascript] || options[:skip_hotwire]
turbo_rails_entry =
- GemfileEntry.version("turbo-rails", ">= 0.7.11", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]")
+ GemfileEntry.version("turbo-rails", ">= 0.9.0", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]")
stimulus_rails_entry =
- GemfileEntry.version("stimulus-rails", ">= 0.4.0", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]")
+ GemfileEntry.version("stimulus-rails", ">= 0.7.3", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]")
[ turbo_rails_entry, stimulus_rails_entry ]
end
def using_node?
options[:javascript] && options[:javascript] != "importmap"
end
+ # CSS processors other than Tailwind require a node-based JavaScript environment. So overwrite the normal JS default
+ # if one such processor has been specified.
+ def adjusted_javascript_option
+ if options[:css] && options[:css] != "tailwind" && options[:javascript] == "importmap"
+ "esbuild"
+ else
+ options[:javascript]
+ end
+ end
+
def css_gemfile_entry
return [] unless options[:css]
if !using_node? && options[:css] == "tailwind"
- GemfileEntry.version("tailwindcss-rails", ">= 0.4.3", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]")
+ GemfileEntry.version("tailwindcss-rails", ">= 0.5.3", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]")
else
- GemfileEntry.version("cssbundling-rails", ">= 0.1.0", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]")
+ GemfileEntry.version("cssbundling-rails", ">= 0.2.7", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]")
end
end
def psych_gemfile_entry
return [] unless defined?(Rubinius)
@@ -385,12 +415,12 @@
end
def run_javascript
return if options[:skip_javascript] || !bundle_install?
- case options[:javascript]
+ case adjusted_javascript_option
when "importmap" then rails_command "importmap:install"
- when "webpack", "esbuild", "rollup" then rails_command "javascript:install:#{options[:javascript]}"
+ when "webpack", "esbuild", "rollup" then rails_command "javascript:install:#{adjusted_javascript_option}"
end
end
def run_hotwire
return if options[:skip_javascript] || options[:skip_hotwire] || !bundle_install?