Skip to content

Commit 64ff6bc

Browse files
committed
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.
1 parent a8cbb96 commit 64ff6bc

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

actiontext/lib/generators/action_text/install/install_generator.rb

+11-17
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ class InstallGenerator < ::Rails::Generators::Base
99
source_root File.expand_path("templates", __dir__)
1010

1111
def install_javascript_dependencies
12-
run "rake app:update:bin"
12+
rails_command "app:update:bin"
1313

14-
say "Installing JavaScript dependencies"
14+
say "Installing JavaScript dependencies", :green
1515
run "yarn add #{js_dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")}",
1616
abort_on_failure: true, capture: true
1717
end
1818

1919
def append_dependencies_to_package_file
20-
app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")
21-
22-
if app_javascript_pack_path.exist?
23-
js_dependencies.keys.each do |name|
24-
line = %[require("#{name}")]
20+
if (app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")).exist?
21+
js_dependencies.each_key do |dependency|
22+
line = %[require("#{dependency}")]
2523

2624
unless app_javascript_pack_path.read.include? line
27-
say "Adding #{name} to #{app_javascript_pack_path}"
25+
say "Adding #{dependency} to #{app_javascript_pack_path}", :green
2826
append_to_file app_javascript_pack_path, "\n#{line}"
2927
end
3028
end
3129
else
32-
warn <<~WARNING
30+
say <<~WARNING, :red
3331
WARNING: Action Text can't locate your JavaScript bundle to add its package dependencies.
3432
3533
Add these lines to any bundles:
@@ -47,13 +45,11 @@ def create_actiontext_files
4745
template "actiontext.scss", "app/assets/stylesheets/actiontext.scss"
4846

4947
copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb",
50-
"app/views/active_storage/blobs/_blob.html.erb"
48+
"app/views/active_storage/blobs/_blob.html.erb"
5149
end
5250

5351
def create_migrations
54-
run "rake active_storage:install:migrations"
55-
run "rake railties:install:migrations"
56-
run "rake action_text:install:migrations"
52+
rails_command "railties:install:migrations FROM=active_storage,action_text"
5753
end
5854

5955
hook_for :test_framework
@@ -62,10 +58,8 @@ def create_migrations
6258
GEM_ROOT = "#{__dir__}/../../../.."
6359

6460
def js_dependencies
65-
package_contents = File.read(Pathname.new("#{GEM_ROOT}/package.json"))
66-
js_package = JSON.load(package_contents)
67-
68-
js_package["peerDependencies"].dup.merge \
61+
js_package = JSON.load(Pathname.new("#{GEM_ROOT}/package.json"))
62+
js_package["peerDependencies"].merge \
6963
js_package["name"] => "^#{js_package["version"]}"
7064
end
7165
end

0 commit comments

Comments
 (0)