aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/app_base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/generators/app_base.rb')
-rw-r--r--railties/lib/rails/generators/app_base.rb67
1 files changed, 63 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 91342c592c..87f6f01750 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -30,9 +30,12 @@ module Rails
class_option :database, type: :string, aliases: "-d", default: "sqlite3",
desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
- class_option :javascript, type: :string, aliases: "-j", default: "jquery",
+ class_option :javascript, type: :string, aliases: "-j",
desc: "Preconfigure for selected JavaScript library"
+ class_option :yarn, type: :boolean, default: false,
+ desc: "Preconfigure for assets management with Yarn"
+
class_option :skip_gemfile, type: :boolean, default: false,
desc: "Don't create a Gemfile"
@@ -67,6 +70,9 @@ module Rails
class_option :skip_listen, type: :boolean, default: false,
desc: "Don't generate configuration that depends on the listen gem"
+ class_option :skip_coffee, type: :boolean, default: false,
+ desc: "Don't use CoffeeScript"
+
class_option :skip_javascript, type: :boolean, aliases: "-J", default: false,
desc: "Skip JavaScript files"
@@ -322,9 +328,13 @@ module Rails
if options[:skip_javascript] || options[:skip_sprockets]
[]
else
- gems = [coffee_gemfile_entry, javascript_runtime_gemfile_entry]
- gems << GemfileEntry.version("#{options[:javascript]}-rails", nil,
- "Use #{options[:javascript]} as the JavaScript library")
+ gems = [javascript_runtime_gemfile_entry]
+ gems << coffee_gemfile_entry unless options[:skip_coffee]
+
+ if options[:javascript]
+ gems << GemfileEntry.version("#{options[:javascript]}-rails", nil,
+ "Use #{options[:javascript]} as the JavaScript library")
+ end
unless options[:skip_turbolinks]
gems << GemfileEntry.version("turbolinks", "~> 5",
@@ -404,6 +414,55 @@ module Rails
bundle_command("install") if bundle_install?
end
+ def run_yarn
+ if package_json_exist?
+ if yarn_path
+ say_status :run, "yarn install"
+ yarn_command("install")
+ else
+ say_status :warning, "yarn option passed but Yarn executable was not detected in the system.", :yellow
+ say_status :warning, "Download Yarn at https://yarnpkg.com/en/docs/install", :yellow
+ end
+ end
+ end
+
+ def package_json_exist?
+ File.exist?("vendor/package.json")
+ end
+
+ def yarn_path
+ commands = ["yarn"]
+
+ if Gem.win_platform?
+ ENV["PATHEXT"].split(File::PATH_SEPARATOR).each do |ext|
+ commands << commands[0] + ext
+ end
+ end
+
+ yarn_path = commands.find do |cmd|
+ paths = ENV["PATH"].split(File::PATH_SEPARATOR)
+
+ path = paths.find do |p|
+ full_path = File.expand_path(cmd, p)
+ File.executable?(full_path) && File.file?(full_path)
+ end
+
+ path && File.expand_path(cmd, path)
+ end
+
+ yarn_path
+ end
+
+ def yarn_command(command)
+ full_command = "#{yarn_path} #{command}"
+
+ if options[:quiet]
+ system(full_command, out: File::NULL)
+ else
+ system(full_command)
+ end
+ end
+
def generate_spring_binstubs
if bundle_install? && spring_install?
bundle_command("exec spring binstub --all")