lib/rails/generators/app_base.rb in railties-7.0.0.rc3 vs lib/rails/generators/app_base.rb in railties-7.0.0
- old
+ new
@@ -98,11 +98,12 @@
class_option :help, type: :boolean, aliases: "-h", group: :rails,
desc: "Show this help message and quit"
end
- def initialize(*)
+ def initialize(positional_argv, option_argv, *)
+ @argv = [*positional_argv, *option_argv]
@gem_filter = lambda { |gem| true }
super
end
private
@@ -170,14 +171,14 @@
def asset_pipeline_gemfile_entry
return [] if options[:skip_asset_pipeline]
if options[:asset_pipeline] == "sprockets"
- GemfileEntry.version "sprockets-rails", ">= 3.4.1",
+ GemfileEntry.floats "sprockets-rails",
"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/]"
+ GemfileEntry.floats "propshaft", "The modern asset pipeline for Rails [https://github.com/rails/propshaft]"
else
[]
end
end
@@ -253,10 +254,14 @@
def self.version(name, version, comment = nil)
new(name, version, comment)
end
+ def self.floats(name, comment = nil)
+ new(name, nil, comment)
+ end
+
def self.path(name, path, comment = nil)
new(name, nil, comment, path: path)
end
def version
@@ -266,30 +271,34 @@
version.join('", "')
else
version
end
end
+
+ def to_s
+ [ ("# #{comment}\n" if comment),
+ ("# " if commented_out), "gem \"#{name}\"", (", \"#{version}\"" if version),
+ *options.map { |key, val| ", #{key}: #{val.inspect}" }
+ ].compact.join
+ end
end
+ def rails_prerelease?
+ options.dev? || options.edge? || options.main?
+ end
+
def rails_gemfile_entry
if options.dev?
- [
- GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH, "Use local checkout of Rails")
- ]
+ GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH, "Use local checkout of Rails")
elsif options.edge?
edge_branch = Rails.gem_version.prerelease? ? "main" : [*Rails.gem_version.segments.first(2), "stable"].join("-")
- [
- GemfileEntry.github("rails", "rails/rails", edge_branch, "Use specific branch of Rails")
- ]
+ GemfileEntry.github("rails", "rails/rails", edge_branch, "Use specific branch of Rails")
elsif options.main?
- [
- GemfileEntry.github("rails", "rails/rails", "main", "Use main development branch of Rails")
- ]
+ GemfileEntry.github("rails", "rails/rails", "main", "Use main development branch of Rails")
else
- [GemfileEntry.version("rails",
- rails_version_specifier,
- %(Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"))]
+ GemfileEntry.version("rails", rails_version_specifier,
+ %(Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"))
end
end
def rails_version_specifier(gem_version = Rails.gem_version)
if gem_version.segments.size == 3 || gem_version.release.segments.size == 3
@@ -304,32 +313,31 @@
end
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.11", comment, {}, options[:api]
+ GemfileEntry.new "jbuilder", nil, "Build JSON APIs with ease [https://github.com/rails/jbuilder]", {}, options[:api]
end
def javascript_gemfile_entry
return [] if options[:skip_javascript]
if adjusted_javascript_option == "importmap"
- GemfileEntry.version("importmap-rails", ">= 0.9.2", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]")
+ GemfileEntry.floats "importmap-rails", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]"
else
- GemfileEntry.version "jsbundling-rails", ">= 0.2.2", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]"
+ GemfileEntry.floats "jsbundling-rails", "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.9.0", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]")
+ GemfileEntry.floats "turbo-rails", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]"
stimulus_rails_entry =
- GemfileEntry.version("stimulus-rails", ">= 0.7.3", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]")
+ GemfileEntry.floats "stimulus-rails", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]"
[ turbo_rails_entry, stimulus_rails_entry ]
end
def using_node?
@@ -348,13 +356,13 @@
def css_gemfile_entry
return [] unless options[:css]
if !using_node? && options[:css] == "tailwind"
- GemfileEntry.version("tailwindcss-rails", ">= 0.5.3", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]")
+ GemfileEntry.floats "tailwindcss-rails", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]"
else
- GemfileEntry.version("cssbundling-rails", ">= 0.2.7", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]")
+ GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]"
end
end
def psych_gemfile_entry
return [] unless defined?(Rubinius)
@@ -406,9 +414,31 @@
!(options[:skip_system_test] || options[:skip_test] || options[:api])
end
def depend_on_bootsnap?
!options[:skip_bootsnap] && !options[:dev] && !defined?(JRUBY_VERSION)
+ end
+
+ def target_rails_prerelease(self_command = "new")
+ return unless rails_prerelease? && bundle_install?
+
+ if !File.exist?(File.expand_path("Gemfile", destination_root))
+ create_file("Gemfile", <<~GEMFILE)
+ source "https://rubygems.org"
+ git_source(:github) { |repo| "https://github.com/\#{repo}.git" }
+ #{rails_gemfile_entry}
+ GEMFILE
+
+ run_bundle
+
+ @argv[0] = destination_root
+ require "shellwords"
+ bundle_command("exec rails #{self_command} #{Shellwords.join(@argv)}")
+ exit
+ else
+ remove_file("Gemfile")
+ remove_file("Gemfile.lock")
+ end
end
def run_bundle
bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
end