shakacode / shakapacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
417 stars 91 forks source link

Simplify Bin Files #494

Open justin808 opened 3 months ago

justin808 commented 3 months ago

If we use the binstubs for a pre-compilation task, like always generating some files, then let's simplify and document the bin files.

The point is to make the binstub as compact as possible so that any customizations can be identified more easily.

Current bin file https://github.com/shakacode/shakapacker/blob/main/lib/install/bin/shakapacker has:

#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= "development"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)

require "bundler/setup"
require "shakapacker"
require "shakapacker/webpack_runner"

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
  Shakapacker::WebpackRunner.run(ARGV)
end

How about something like that is easier to read and modify?

#!/usr/bin/env ruby
require "shakapacker/binstub"

# Insert code here to always run before compilation

Shakapacker::Binstub.compile(ARGV)

And the same for the https://github.com/shakacode/shakapacker/blob/main/lib/install/bin/shakapacker-dev-server

tomdracz commented 3 months ago

Sorry, I don't quite follow the part here

If we'll use the binstubs for a pre-compilation task, like always generating some files, then let's simplify and document the bin files.

What do you mean around using binstubs for pre-compilation task?

Would proposed approach literally move the code in binstub to some shakapacker/binstub file? What's the use case and benefit of adding extra code there rather than to the current generated binstub?

justin808 commented 3 months ago

The point is to make the binstub as compact as possible so that any customizations can be identified more easily.