Skip to content

Commit 60e9424

Browse files
committed
Allow "upgrades" from existing react apps
react_ujs and the autorequiring of components is new in master. The install generator now accounts for some application.js files already having react installed.
1 parent 3a42694 commit 60e9424

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/generators/react/install_generator.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ def create_directory
1717
end
1818

1919
def inject_react
20-
require_react = "//= require react\n//= require react_ujs\n//= require components\n"
21-
22-
manifest = Pathname.new(destination_root).join('app/assets/javascripts',
23-
'application.js')
20+
require_react = "//= require react\n"
2421

2522
if manifest.exist?
2623
manifest_contents = File.read(manifest)
@@ -37,11 +34,25 @@ def inject_react
3734
end
3835
end
3936

37+
def inject_components
38+
inject_into_file manifest, "//= require components\n", {after: "//= require react\n"}
39+
end
40+
41+
def inject_react_ujs
42+
inject_into_file manifest, "//= require react_ujs\n", {after: "//= require react\n"}
43+
end
44+
4045
def create_components
4146
components_js = "//= require_tree ./components\n"
4247
components_file = File.join(*%w(app assets javascripts components.js))
4348
create_file components_file, components_js
4449
end
50+
51+
private
52+
53+
def manifest
54+
Pathname.new(destination_root).join('app/assets/javascripts', 'application.js')
55+
end
4556
end
4657
end
4758
end

0 commit comments

Comments
 (0)