Skip to content

Commit

Permalink
Fix copy-pasta, and use plugin on install instead of foreman
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Jan 3, 2024
1 parent cd042db commit 0bc1289
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak
While you're developing your application, you want to run Tailwind in "watch" mode, so changes are automatically reflected in the generated CSS output. You can do this by:

- running `rails tailwindcss:watch` as a separate process,
- or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to start both the Tailwind watch process and the rails server in development mode.
- or by using the puma plugin

If you are running `rails tailwindcss:watch` on a system that doesn't fully support file system events, pass a `poll` argument to the task to instruct tailwindcss to instead use polling: `rails tailwindcss:watch[poll]`. If you use `bin/dev` then you should modify your `Procfile.dev`.

Expand Down
2 changes: 0 additions & 2 deletions lib/install/Procfile.dev

This file was deleted.

8 changes: 0 additions & 8 deletions lib/install/dev

This file was deleted.

15 changes: 2 additions & 13 deletions lib/install/tailwindcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,8 @@
copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
end

if Rails.root.join("Procfile.dev").exist?
append_to_file "Procfile.dev", "css: bin/rails tailwindcss:watch\n"
else
say "Add default Procfile.dev"
copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"

say "Ensure foreman is installed"
run "gem install foreman"
end

say "Add bin/dev to start foreman"
copy_file "#{__dir__}/dev", "bin/dev"
chmod "bin/dev", 0755, verbose: false
say "Add puma plugin"
append_to_file "config/puma.rb", %(plugin :tailwindcss if Rails.env.development?)

say "Compile initial Tailwind build"
run "rails tailwindcss:build"
6 changes: 2 additions & 4 deletions lib/puma/plugin/tailwindcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
attr_reader :puma_pid, :tailwind_pid, :log_writer

def start(launcher)
return unless Rails.env.development?

@log_writer = launcher.log_writer
@puma_pid = $$
@tailwind_pid = fork do
Thread.new { monitor_puma }
system(*Tailwindcss::Commands.watch_command)
end

launcher.events.on_stopped { stop_solid_queue }
launcher.events.on_stopped { stop_tailwind }

in_background do
monitor_tailwind
end
end

private
def stop_solid_queue
def stop_tailwind
Process.waitpid(tailwind_pid, Process::WNOHANG)
log "Stopping tailwind..."
Process.kill(:INT, tailwind_pid) if tailwind_pid
Expand Down

0 comments on commit 0bc1289

Please sign in to comment.