Skip to content

Commit 7bdc18b

Browse files
ihabadhamclaude
andcommitted
feat: upgrade to React on Rails v16 enhanced bin/dev and Procfile system
- Update bin/dev to use new ReactOnRails::Dev::ServerManager from PR #1790 - Add support for multiple development modes: * bin/dev (HMR development) - default mode * bin/dev static - static assets with auto-recompilation * bin/dev prod - production-optimized assets * bin/dev kill - clean process termination * bin/dev help - comprehensive help system - Rename Procfile.dev-static to Procfile.dev-static-assets for v16 convention - Add Procfile.dev-prod-assets for production-like asset development - Preserve project-specific customizations (ReScript, locale tasks) - Enhanced developer experience with better UI, error handling, and process management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fd008ad commit 7bdc18b

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

Procfile.dev-prod-assets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Procfile for development with production assets
2+
# Uses production-optimized, precompiled assets with development environment
3+
# Uncomment additional processes as needed for your app
4+
5+
rails: bundle exec rails s -p 3001
6+
rescript: yarn res:dev
7+
# sidekiq: bundle exec sidekiq -C config/sidekiq.yml
8+
# redis: redis-server # Redis is already running system-wide
9+
# mailcatcher: mailcatcher --foreground
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# Procfile for development with static asset compilation
12
# You can run these commands in separate shells
2-
web: rails s -p 3000
3-
redis: redis-server
3+
web: bin/rails server -p 3000
4+
rescript: yarn res:dev
5+
# redis: redis-server # Redis is already running system-wide
46

57
# Next line runs a watch process with webpack to compile the changed files.
68
# When making frequent changes to client side assets, you will prefer building webpack assets
79
# upon saving rather than when you refresh your browser page.
810
# Note, if using React on Rails localization you will need to run
911
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
12+
js: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

bin/dev

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
def installed?(process)
5-
IO.popen "#{process} -v"
6-
rescue Errno::ENOENT
7-
false
8-
end
4+
# ReactOnRails Development Server
5+
#
6+
# This script provides a simple interface to the ReactOnRails development
7+
# server management. The core logic is implemented in ReactOnRails::Dev
8+
# classes for better maintainability and testing.
9+
#
10+
# Each command uses a specific Procfile for process management:
11+
# - bin/dev (default/hmr): Uses Procfile.dev
12+
# - bin/dev static: Uses Procfile.dev-static-assets
13+
# - bin/dev prod: Uses Procfile.dev-prod-assets
14+
#
15+
# To customize development environment:
16+
# 1. Edit the appropriate Procfile to modify which processes run
17+
# 2. Modify this script for project-specific command-line behavior
18+
# 3. Extend ReactOnRails::Dev classes in your Rails app for advanced customization
19+
# 4. Use classes directly: ReactOnRails::Dev::ServerManager.start(:development, "Custom.procfile")
920

10-
def run(process)
11-
system "#{process} start -f Procfile.dev"
12-
rescue Errno::ENOENT
13-
warn <<~MSG
14-
ERROR:
15-
Please ensure `Procfile.dev` exists in your project!
16-
MSG
17-
exit!
21+
begin
22+
require "bundler/setup"
23+
require "react_on_rails/dev"
24+
rescue LoadError
25+
# Fallback for when gem is not yet installed
26+
puts "Loading ReactOnRails development tools..."
27+
require_relative "../../lib/react_on_rails/dev"
1828
end
1929

20-
if installed? "overmind"
21-
run "overmind"
22-
elsif installed? "foreman"
23-
run "foreman"
30+
# Main execution
31+
case ARGV[0]
32+
when "production-assets", "prod"
33+
ReactOnRails::Dev::ServerManager.start(:production_like, "Procfile.dev-prod-assets")
34+
when "static"
35+
ReactOnRails::Dev::ServerManager.start(:static, "Procfile.dev-static-assets")
36+
when "kill"
37+
ReactOnRails::Dev::ServerManager.kill_processes
38+
when "help", "--help", "-h"
39+
ReactOnRails::Dev::ServerManager.show_help
40+
when "hmr", nil
41+
ReactOnRails::Dev::ServerManager.start(:development, "Procfile.dev")
2442
else
25-
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.
28-
MSG
29-
exit!
30-
end
43+
puts "Unknown argument: #{ARGV[0]}"
44+
puts "Run 'bin/dev help' for usage information"
45+
exit 1
46+
end

0 commit comments

Comments
 (0)