From 5d487c95f223fe6303d7e31f5151ec7fb864af1a Mon Sep 17 00:00:00 2001 From: Trinity Takei Date: Mon, 24 Jun 2024 18:29:23 +0200 Subject: [PATCH] Look for tailwind.config.js in Rails.root, app/**, config/** --- .../phlex/install/install_generator.rb | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/generators/phlex/install/install_generator.rb b/lib/generators/phlex/install/install_generator.rb index ecbd734..7d05725 100644 --- a/lib/generators/phlex/install/install_generator.rb +++ b/lib/generators/phlex/install/install_generator.rb @@ -5,7 +5,6 @@ class InstallGenerator < ::Rails::Generators::Base source_root File.expand_path("templates", __dir__) APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb") - TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js") def autoload_components return unless APPLICATION_CONFIGURATION_PATH.exist? @@ -38,9 +37,9 @@ def autoload_views end def configure_tailwind - return unless TAILWIND_CONFIGURATION_PATH.exist? + return unless tailwind_configuration_path.exist? - insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do + insert_into_file tailwind_configuration_path, after: "content: [" do "\n './app/views/**/*.rb'," \ end end @@ -56,5 +55,20 @@ def create_application_layout def create_application_view template "application_view.rb", Rails.root.join("app/views/application_view.rb") end + + private + + def tailwind_configuration_path + @_tailwind_configuration_path ||= + Pathname.new(tailwind_configuration_files.first) + end + + def tailwind_configuration_files + Dir.glob([ + "#{Rails.root}/tailwind.config.js", + "#{Rails.root}/app/**/tailwind.config.js", + "#{Rails.root}/config/**/tailwind.config.js" + ]) + end end end