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
Rails.root
app/**
config/**
🤔
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".
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 theRails.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 thetailwind-rails
generator, orapp/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 (likenode_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 inRails.root
, this application is not using Tailwind, thus there's no need to apply any changes totailwind.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".