Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bin/shakapacker to auto-generate packs #1630

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.development_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem "amazing_print"

group :development, :test do
gem "listen"
gem "debug"
gem "pry"
gem "pry-byebug"
gem "pry-doc"
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ GEM
tins (~> 1.6)
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.0)
docile (1.4.0)
drb (2.2.0)
Expand Down Expand Up @@ -390,6 +393,7 @@ DEPENDENCIES
capybara
capybara-screenshot
coveralls
debug
equivalent-xml
generator_spec
jbuilder
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/Procfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# You can run these commands in separate shells
rails: bundle exec rails s -p 3000
wp-client: bin/shakapacker-dev-server
wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
wp-server: SERVER_BUNDLE_ONLY=true bin/shakapacker --watch

# Bundle ReScript .res files
rescript: yarn build:rescript:dev
10 changes: 10 additions & 0 deletions spec/dummy/bin/shakapacker
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ ENV["RAILS_ENV"] ||= "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)

require "rake"

# Recommendation is to generate packs before compilation.
# SERVER_BUNDLE_ONLY is true when also running the bin/shakapacker-dev-server,
# so no need to run twice.
unless ENV["SERVER_BUNDLE_ONLY"] == "true"
Rake.application.load_rakefile
Rake::Task["react_on_rails:generate_packs"].invoke
end
Comment on lines +14 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional execution logic is clear and well-commented.

However, consider adding error handling for the Rake task invocation to manage potential failures gracefully.

-  Rake::Task["react_on_rails:generate_packs"].invoke
+  begin
+    Rake::Task["react_on_rails:generate_packs"].invoke
+  rescue Exception => e
+    puts "Failed to generate packs: #{e.message}"
+    exit 1
+  end
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Recommendation is to generate packs before compilation.
# SERVER_BUNDLE_ONLY is true when also running the bin/shakapacker-dev-server,
# so no need to run twice.
unless ENV["SERVER_BUNDLE_ONLY"] == "true"
Rake.application.load_rakefile
Rake::Task["react_on_rails:generate_packs"].invoke
end
# Recommendation is to generate packs before compilation.
# SERVER_BUNDLE_ONLY is true when also running the bin/shakapacker-dev-server,
# so no need to run twice.
unless ENV["SERVER_BUNDLE_ONLY"] == "true"
Rake.application.load_rakefile
begin
Rake::Task["react_on_rails:generate_packs"].invoke
rescue Exception => e
puts "Failed to generate packs: #{e.message}"
exit 1
end
end


APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Shakapacker::WebpackRunner.run(ARGV)
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/bin/shakapacker-dev-server
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ require "bundler/setup"
require "shakapacker"
require "shakapacker/dev_server_runner"

# Recommendation is to generate packs before compilation
Rake.application.load_rakefile
Rake::Task["react_on_rails:generate_packs"].invoke

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Shakapacker::DevServerRunner.run(ARGV)
Expand Down
Loading
Loading