phlex-ruby / phlex-rails

An object-oriented alternative to ActionView for Ruby on Rails.
https://www.phlex.fun
MIT License
232 stars 40 forks source link

Look up tailwind.config.js anywhere in the app directory (except dirs ignored explicitly) #204

Closed trinitytakei closed 2 months ago

trinitytakei commented 5 months ago

The Problem

As discussed here: https://discord.com/channels/1082611227827638303/1254781033791098940 , tailwind.config.js can show up in several places in a Rails app, based on how/when you installed Tailwind.

However, the Phlex install generator currently assumes that tailwind.config.js should always be in the Rails.root directory. This can lead to some surprises if the user installing Phlex has the file somewhere else (config/tailwind.config.js if installed with the tailwind-rails generator, or app/javascript/stylesheets/tailwind.config.js for older (I'm guessing webpacker) apps; possibly other places, depending on your JS bundler config and whatnot).

The Proposed Solution

This PR aims to rectify the situation by looking up the location of tailwind.config.js. Except some directories explicitly ignored by the generator (like node_modules, vendor and such), it will look fortailwind.config.js anywhere in the app directory.

EDIT after @joeldrapper's review: It's cleaner and more maintainable to go with the whitelist approach ("look here: ... ") than the blacklist one ("look anywhere BUT here: ..."). Just keep in mind that your tailwind.config.js config has to be in either

🤔

I'm assuming the previous implementation semantic was something like "If tailwind.config.js is not in Rails.root, this application is not using Tailwind, thus there's no need to apply any changes to tailwind.config.js, kthxbye".

The current one is along the lines of "If you are using Tailwind, and you are not doing something extremely crazy (like having multiple tailwind.config.js files or storing them outside of the sensible directories (Rails.root, app/**, config/**), we'll find the file and apply the modifications".

joeldrapper commented 3 months ago

Thanks for opening this and sorry it took so long to review.

trinitytakei commented 3 months ago

No worries, summer is slow season over here as well!

trinitytakei commented 3 months ago

@joeldrapper I believe this is good to go as well (at least Rubocop / bin/test are 🟢).