Skip to content

Commit 94f0920

Browse files
committed
refactor generators: eliminate wasteful cleanup
- Clean Base: Make BaseGenerator conditional based on Redux option - Only create HelloWorld structure for non-Redux components - Only copy HelloWorld.module.css for non-Redux components - Simplify Redux: Remove cleanup_base_generator_files method entirely - Result: Eliminates wasteful create-then-delete pattern - Verified: Both non-Redux (HelloWorld) and Redux (HelloWorldApp) work correctly This approach is much cleaner since auto-registration is now the default behavior.
1 parent bb1e45d commit 94f0920

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/generators/react_on_rails/base_generator.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ def add_hello_world_route
2222
end
2323

2424
def create_react_directories
25-
# Create auto-registration directory structure
26-
empty_directory("app/javascript/src/HelloWorld/ror_components")
25+
# Create auto-registration directory structure for non-Redux components only
26+
# Redux components handle their own directory structure
27+
unless options.redux?
28+
empty_directory("app/javascript/src/HelloWorld/ror_components")
29+
end
2730
end
2831

2932
def copy_base_files
@@ -42,8 +45,14 @@ def copy_base_files
4245

4346
def copy_js_bundle_files
4447
base_path = "base/base/"
45-
base_files = %w[app/javascript/packs/server-bundle.js
46-
app/javascript/src/HelloWorld/HelloWorld.module.css]
48+
base_files = %w[app/javascript/packs/server-bundle.js]
49+
50+
# Only copy HelloWorld.module.css for non-Redux components
51+
# Redux components handle their own CSS files
52+
unless options.redux?
53+
base_files << "app/javascript/src/HelloWorld/HelloWorld.module.css"
54+
end
55+
4756
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
4857
end
4958

lib/generators/react_on_rails/react_with_redux_generator.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ def add_redux_yarn_dependencies
6262
run "yarn add redux react-redux"
6363
end
6464

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-
7265
def add_redux_specific_messages
7366
# Override the generic messages with Redux-specific instructions
7467
require_relative "generator_messages"

0 commit comments

Comments
 (0)