@@ -7,24 +7,151 @@ rescue Errno::ENOENT
77 false
88end
99
10- def run ( process )
11- system "#{ process } start -f Procfile.dev"
10+ def generate_packs
11+ puts "Generating React on Rails packs..."
12+ system "bundle exec rake react_on_rails:generate_packs"
13+
14+ unless $?. success?
15+ puts "Pack generation failed"
16+ exit 1
17+ end
18+ end
19+
20+ def run_production_like
21+ puts "Starting production-like development server..."
22+ puts " - Generating React on Rails packs"
23+ puts " - Precompiling assets with production optimizations"
24+ puts " - Running Rails server on port 3001"
25+ puts " - No HMR (Hot Module Replacement)"
26+ puts " - CSS extracted to separate files (no FOUC)"
27+ puts ""
28+ puts "Access at: http://localhost:3001"
29+ puts ""
30+
31+ # Generate React on Rails packs first
32+ generate_packs
33+
34+ # Precompile assets in production mode
35+ puts "Precompiling assets..."
36+ system "RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile"
37+
38+ if $?. success?
39+ puts "Assets precompiled successfully"
40+ puts "Starting Rails server in production mode..."
41+ puts ""
42+ puts "Press Ctrl+C to stop the server"
43+ puts "To clean up: rm -rf public/packs && bin/dev"
44+ puts ""
45+
46+ # Start Rails in production mode
47+ system "RAILS_ENV=production bundle exec rails server -p 3001"
48+ else
49+ puts "Asset precompilation failed"
50+ exit 1
51+ end
52+ end
53+
54+ def run_static_development
55+ puts "Starting development server with static assets..."
56+ puts " - Generating React on Rails packs"
57+ puts " - Using shakapacker --watch (no HMR)"
58+ puts " - CSS extracted to separate files (no FOUC)"
59+ puts " - Development environment (source maps, faster builds)"
60+ puts " - Auto-recompiles on file changes"
61+ puts ""
62+ puts "Access at: http://localhost:3000"
63+ puts ""
64+
65+ # Generate React on Rails packs first
66+ generate_packs
67+
68+ if installed? "overmind"
69+ system "overmind start -f Procfile.dev-static"
70+ elsif installed? "foreman"
71+ system "foreman start -f Procfile.dev-static"
72+ else
73+ warn <<~MSG
74+ NOTICE:
75+ For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
76+ MSG
77+ exit!
78+ end
1279rescue Errno ::ENOENT
1380 warn <<~MSG
1481 ERROR:
15- Please ensure `Procfile.dev` exists in your project!
82+ Please ensure `Procfile.dev-static ` exists in your project!
1683 MSG
1784 exit!
1885end
1986
20- if installed? "overmind"
21- run "overmind"
22- elsif installed? "foreman"
23- run "foreman "
24- else
87+ def run_development ( process )
88+ generate_packs
89+
90+ system " #{ process } start -f Procfile.dev "
91+ rescue Errno :: ENOENT
2592 warn <<~MSG
26- NOTICE :
27- For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
93+ ERROR :
94+ Please ensure `Procfile.dev` exists in your project!
2895 MSG
2996 exit!
3097end
98+
99+ # Check for arguments
100+ if ARGV [ 0 ] == "production-assets" || ARGV [ 0 ] == "prod"
101+ run_production_like
102+ elsif ARGV [ 0 ] == "static"
103+ run_static_development
104+ elsif ARGV [ 0 ] == "help" || ARGV [ 0 ] == "--help" || ARGV [ 0 ] == "-h"
105+ puts <<~HELP
106+ Usage: bin/dev [command]
107+
108+ Commands:
109+ (none) / hmr Start development server with HMR (default)
110+ static Start development server with static assets (no HMR, no FOUC)
111+ production-assets Start with production-optimized assets (no HMR)
112+ prod Alias for production-assets
113+ help Show this help message
114+
115+ HMR Development mode (default):
116+ - Hot Module Replacement (HMR) enabled
117+ - Automatic React on Rails pack generation
118+ - Source maps for debugging
119+ - May have Flash of Unstyled Content (FOUC)
120+ - Fast recompilation
121+ - Access at: http://localhost:3000
122+
123+ Static development mode:
124+ - No HMR (static assets with auto-recompilation)
125+ - Automatic React on Rails pack generation
126+ - CSS extracted to separate files (no FOUC)
127+ - Development environment (faster builds than production)
128+ - Source maps for debugging
129+ - Access at: http://localhost:3000
130+
131+ Production-like mode:
132+ - Automatic React on Rails pack generation
133+ - Optimized, minified bundles
134+ - Extracted CSS files (no FOUC)
135+ - No HMR (static assets)
136+ - Slower recompilation
137+ - Access at: http://localhost:3001
138+ HELP
139+ elsif ARGV [ 0 ] == "hmr" || ARGV [ 0 ] . nil?
140+ # Default development mode (HMR)
141+ if installed? "overmind"
142+ run_development "overmind"
143+ elsif installed? "foreman"
144+ run_development "foreman"
145+ else
146+ warn <<~MSG
147+ NOTICE:
148+ For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
149+ MSG
150+ exit!
151+ end
152+ else
153+ # Unknown argument
154+ puts "Unknown argument: #{ ARGV [ 0 ] } "
155+ puts "Run 'bin/dev help' for usage information"
156+ exit 1
157+ end
0 commit comments