From 0bc1289927dbf666e0d1f0bd79380fa53b1d188b Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 3 Jan 2024 10:05:22 -0500 Subject: [PATCH] Fix copy-pasta, and use plugin on install instead of foreman --- README.md | 2 +- lib/install/Procfile.dev | 2 -- lib/install/dev | 8 -------- lib/install/tailwindcss.rb | 15 ++------------- lib/puma/plugin/tailwindcss.rb | 6 ++---- 5 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 lib/install/Procfile.dev delete mode 100755 lib/install/dev diff --git a/README.md b/README.md index 76aa66e..9cba30b 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/lib/install/Procfile.dev b/lib/install/Procfile.dev deleted file mode 100644 index 59915d5..0000000 --- a/lib/install/Procfile.dev +++ /dev/null @@ -1,2 +0,0 @@ -web: env RUBY_DEBUG_OPEN=true bin/rails server -p 3000 -css: bin/rails tailwindcss:watch diff --git a/lib/install/dev b/lib/install/dev deleted file mode 100755 index 74ade16..0000000 --- a/lib/install/dev +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -if ! gem list foreman -i --silent; then - echo "Installing foreman..." - gem install foreman -fi - -exec foreman start -f Procfile.dev "$@" diff --git a/lib/install/tailwindcss.rb b/lib/install/tailwindcss.rb index 413f86b..f159a37 100644 --- a/lib/install/tailwindcss.rb +++ b/lib/install/tailwindcss.rb @@ -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" diff --git a/lib/puma/plugin/tailwindcss.rb b/lib/puma/plugin/tailwindcss.rb index cb6b5bc..d78b068 100644 --- a/lib/puma/plugin/tailwindcss.rb +++ b/lib/puma/plugin/tailwindcss.rb @@ -4,8 +4,6 @@ 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 @@ -13,7 +11,7 @@ def start(launcher) system(*Tailwindcss::Commands.watch_command) end - launcher.events.on_stopped { stop_solid_queue } + launcher.events.on_stopped { stop_tailwind } in_background do monitor_tailwind @@ -21,7 +19,7 @@ def start(launcher) 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