From 3ada1392e6b82c9be99a7c33bad69c60c2c29d20 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Mon, 25 Sep 2023 23:45:20 -0400 Subject: [PATCH] Fix: Added check for tailwind.config.js based on its path #1764 (#1891) * Fix: Added check for tailwind.config.js based on its path * Fixed code climate issue --- .../avo/tailwindcss/install_generator.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/generators/avo/tailwindcss/install_generator.rb b/lib/generators/avo/tailwindcss/install_generator.rb index abd226e1ab..0207d0b47d 100644 --- a/lib/generators/avo/tailwindcss/install_generator.rb +++ b/lib/generators/avo/tailwindcss/install_generator.rb @@ -39,11 +39,19 @@ def create_files say "Adding the CSS asset to the partial" prepend_to_file Rails.root.join("app", "views", "avo", "partials", "_pre_head.html.erb"), "<%= stylesheet_link_tag \"avo.tailwind.css\", media: \"all\" %>" + tailwind_script = setup_tailwind_script say "Ensure you have the following script in your package.json file.", :yellow - say %("scripts": { "avo:tailwindcss": "tailwindcss -i ./app/assets/stylesheets/avo.tailwind.css -o ./app/assets/builds/avo.tailwind.css --minify" }), :green + say %("scripts": { "avo:tailwindcss": "#{tailwind_script}" --minify }), :green end no_tasks do + def setup_tailwind_script + tailwind_config_path = tailwindcss_config_path() + tailwind_script = "tailwindcss -i ./app/assets/stylesheets/avo.tailwind.css -o ./app/assets/builds/avo.tailwind.css" + tailwind_script += " -c #{tailwind_config_path}" if tailwind_config_path + tailwind_script + end + def template_path(filename) Pathname.new(__dir__).join("..", "templates", "tailwindcss", filename).to_s end @@ -51,6 +59,12 @@ def template_path(filename) def tailwindcss_installed? Rails.root.join("config", "tailwind.config.js").exist? || Rails.root.join("tailwind.config.js").exist? end + + def tailwindcss_config_path + if Rails.root.join("config", "tailwind.config.js").exist? + "./config/tailwind.config.js" + end + end end end end