@@ -9,29 +9,30 @@ class ReactWithReduxGenerator < Rails::Generators::Base
99 source_root ( File . expand_path ( "templates" , __dir__ ) )
1010
1111 def create_redux_directories
12- dirs = %w[ actions constants containers reducers store startup ]
13- dirs . each { |name | empty_directory ( "app/javascript/bundles/HelloWorld/#{ name } " ) }
12+ # Create auto-registration directory structure for Redux
13+ empty_directory ( "app/javascript/src/HelloWorldApp/ror_components" )
14+
15+ # Create Redux support directories within the component directory
16+ dirs = %w[ actions constants containers reducers store ]
17+ dirs . each { |name | empty_directory ( "app/javascript/src/HelloWorldApp/#{ name } " ) }
1418 end
1519
1620 def copy_base_files
1721 base_js_path = "redux/base"
18- base_files = %w[ app/javascript/bundles/HelloWorld/components/HelloWorld.jsx
19- app/javascript/bundles/HelloWorld/components/HelloWorld.module.css ]
20- base_files . each { |file | copy_file ( "#{ base_js_path } /#{ file } " , file ) }
21-
22- # Also copy Redux-connected component to auto-registration structure
22+
23+ # Copy Redux-connected component to auto-registration structure
2324 copy_file ( "#{ base_js_path } /app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.jsx" ,
24- "app/javascript/src/HelloWorld /ror_components/HelloWorld .client.jsx" )
25+ "app/javascript/src/HelloWorldApp /ror_components/HelloWorldApp .client.jsx" )
2526 copy_file ( "#{ base_js_path } /app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.jsx" ,
26- "app/javascript/src/HelloWorld /ror_components/HelloWorld .server.jsx" )
27+ "app/javascript/src/HelloWorldApp /ror_components/HelloWorldApp .server.jsx" )
2728 copy_file ( "#{ base_js_path } /app/javascript/bundles/HelloWorld/components/HelloWorld.module.css" ,
28- "app/javascript/src/HelloWorld/HelloWorld .module.css" )
29+ "app/javascript/src/HelloWorldApp/HelloWorldApp .module.css" )
2930
3031 # Update import paths in client component
31- ror_client_file = "app/javascript/src/HelloWorld /ror_components/HelloWorld .client.jsx"
32- gsub_file ( ror_client_file , "../store/helloWorldStore" , "../../../bundles/HelloWorld/ store/helloWorldStore" )
32+ ror_client_file = "app/javascript/src/HelloWorldApp /ror_components/HelloWorldApp .client.jsx"
33+ gsub_file ( ror_client_file , "../store/helloWorldStore" , "../store/helloWorldStore" )
3334 gsub_file ( ror_client_file , "../containers/HelloWorldContainer" ,
34- "../../../bundles/HelloWorld/ containers/HelloWorldContainer" )
35+ "../containers/HelloWorldContainer" )
3536 end
3637
3738 def copy_base_redux_files
@@ -40,29 +41,42 @@ def copy_base_redux_files
4041 containers/HelloWorldContainer.js
4142 constants/helloWorldConstants.js
4243 reducers/helloWorldReducer.js
43- store/helloWorldStore.js
44- startup/HelloWorldApp.client.jsx
45- startup/HelloWorldApp.server.jsx ] . each do |file |
44+ store/helloWorldStore.js ] . each do |file |
4645 copy_file ( "#{ base_hello_world_path } /#{ file } " ,
47- "app/javascript/bundles/HelloWorld /#{ file } " )
46+ "app/javascript/src/HelloWorldApp /#{ file } " )
4847 end
4948 end
5049
5150 def create_appropriate_templates
5251 base_path = "base/base"
53- base_js_path = "#{ base_path } /app/javascript"
5452 config = {
55- component_name : "HelloWorld" ,
56- app_relative_path : "../bundles/HelloWorld/startup/HelloWorldApp.client"
53+ component_name : "HelloWorldApp"
5754 }
5855
59- template ( "#{ base_js_path } /packs/registration.js.tt" , "app/javascript/packs/hello-world-bundle.js" , config )
60- template ( "#{ base_path } /app/views/hello_world/index.html.erb.tt" , "app/views/hello_world/index.html.erb" , config )
56+ # Only create the view template - no manual bundle needed for auto registration
57+ template ( "#{ base_path } /app/views/hello_world/index.html.erb.tt" ,
58+ "app/views/hello_world/index.html.erb" , config )
6159 end
6260
6361 def add_redux_yarn_dependencies
6462 run "yarn add redux react-redux"
6563 end
64+
65+ def cleanup_base_generator_files
66+ # Remove files created by base generator since Redux uses different structure
67+ remove_file "app/javascript/src/HelloWorld/HelloWorld.module.css"
68+ remove_dir "app/javascript/src/HelloWorld/ror_components" if Dir . exist? ( "app/javascript/src/HelloWorld/ror_components" ) && Dir . empty? ( "app/javascript/src/HelloWorld/ror_components" )
69+ remove_dir "app/javascript/src/HelloWorld" if Dir . exist? ( "app/javascript/src/HelloWorld" ) && Dir . entries ( "app/javascript/src/HelloWorld" ) . size <= 2 # only . and ..
70+ end
71+
72+ def add_redux_specific_messages
73+ # Override the generic messages with Redux-specific instructions
74+ require_relative "generator_messages"
75+ GeneratorMessages . output . clear
76+ GeneratorMessages . add_info (
77+ GeneratorMessages . helpful_message_after_installation ( component_name : "HelloWorldApp" )
78+ )
79+ end
6680 end
6781 end
6882end
0 commit comments