@@ -9,27 +9,25 @@ class InstallGenerator < ::Rails::Generators::Base
9
9
source_root File . expand_path ( "templates" , __dir__ )
10
10
11
11
def install_javascript_dependencies
12
- run "rake app:update:bin"
12
+ rails_command " app:update:bin"
13
13
14
- say "Installing JavaScript dependencies"
14
+ say "Installing JavaScript dependencies" , :green
15
15
run "yarn add #{ js_dependencies . map { |name , version | "#{ name } @#{ version } " } . join ( " " ) } " ,
16
16
abort_on_failure : true , capture : true
17
17
end
18
18
19
19
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 } ")]
25
23
26
24
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
28
26
append_to_file app_javascript_pack_path , "\n #{ line } "
29
27
end
30
28
end
31
29
else
32
- warn <<~WARNING
30
+ say <<~WARNING , :red
33
31
WARNING: Action Text can't locate your JavaScript bundle to add its package dependencies.
34
32
35
33
Add these lines to any bundles:
@@ -47,13 +45,11 @@ def create_actiontext_files
47
45
template "actiontext.scss" , "app/assets/stylesheets/actiontext.scss"
48
46
49
47
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"
51
49
end
52
50
53
51
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"
57
53
end
58
54
59
55
hook_for :test_framework
@@ -62,10 +58,8 @@ def create_migrations
62
58
GEM_ROOT = "#{ __dir__ } /../../../.."
63
59
64
60
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 \
69
63
js_package [ "name" ] => "^#{ js_package [ "version" ] } "
70
64
end
71
65
end
0 commit comments