Tune ActionText::Generators::InstallGenerator

* Use rails_command instead of run (will also print "rails" in the output)
* Generally tune colors: print green for the status updates,
  red for the warning to get the eye.
* Combine migration copying into running one task and pass FROM.
  Generates "create_tables.engine_name.rb" migrations.
* Slim some variables and style the copy_file invocation.
上级 a8cbb96b
......@@ -9,27 +9,25 @@ class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)
def install_javascript_dependencies
run "rake app:update:bin"
rails_command "app:update:bin"
say "Installing JavaScript dependencies"
say "Installing JavaScript dependencies", :green
run "yarn add #{js_dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")}",
abort_on_failure: true, capture: true
end
def append_dependencies_to_package_file
app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")
if app_javascript_pack_path.exist?
js_dependencies.keys.each do |name|
line = %[require("#{name}")]
if (app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")).exist?
js_dependencies.each_key do |dependency|
line = %[require("#{dependency}")]
unless app_javascript_pack_path.read.include? line
say "Adding #{name} to #{app_javascript_pack_path}"
say "Adding #{dependency} to #{app_javascript_pack_path}", :green
append_to_file app_javascript_pack_path, "\n#{line}"
end
end
else
warn <<~WARNING
say <<~WARNING, :red
WARNING: Action Text can't locate your JavaScript bundle to add its package dependencies.
Add these lines to any bundles:
......@@ -47,13 +45,11 @@ def create_actiontext_files
template "actiontext.scss", "app/assets/stylesheets/actiontext.scss"
copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb",
"app/views/active_storage/blobs/_blob.html.erb"
"app/views/active_storage/blobs/_blob.html.erb"
end
def create_migrations
run "rake active_storage:install:migrations"
run "rake railties:install:migrations"
run "rake action_text:install:migrations"
rails_command "railties:install:migrations FROM=active_storage,action_text"
end
hook_for :test_framework
......@@ -62,10 +58,8 @@ def create_migrations
GEM_ROOT = "#{__dir__}/../../../.."
def js_dependencies
package_contents = File.read(Pathname.new("#{GEM_ROOT}/package.json"))
js_package = JSON.load(package_contents)
js_package["peerDependencies"].dup.merge \
js_package = JSON.load(Pathname.new("#{GEM_ROOT}/package.json"))
js_package["peerDependencies"].merge \
js_package["name"] => "^#{js_package["version"]}"
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册