Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Monitor a directory for changes; run a shell script (macOS)
I’m building a Textpattern theme using a CSS framework for presentational elements, and I’m looking to build a shortlist of file / directory watchers to perform the following:
- Watch for changes in a given directory (recursively, ideally).
- When any changes happen, run a shell script.
…and run ad infinitum, until I Ctrl-C it.
So far, fswatch looks like it fits the bill.
Is anyone here doing anything akin to the above process with something that’s not fswatch
? Please leave your advice / feedback here, if it’s appropriate.
Thank you.
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
Ah, so there is someone out there… it’s been quiet around here of late :-)
Not quite the same, but might your favourite coder’s smd_prognostics fit the bill here?
I think adi had another plugin along those lines but need to check. … checking … checking. Well, I was thinking of adi_detritus which isn’t quite the same thing, but he does have a beta plugin called adi_alert in the archive he sent, but that too does not seem to act at the filesystem level; it alerts to changes to a site.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
jakob wrote #340022:
Ah, so there is someone out there… it’s been quiet around here of late :-)
Heh! I was thinking the same. Summer in the northern hemisphere does tend to be a good antidote to screen time.
Not quite the same, but might your favourite coder’s smd_prognostics fit the bill here? I think adi had another plugin along those lines but need to check.
I should have been more specific, I’ll clarify a little.
I’m developing a theme locally on macOS, and I’m using the Tailwind CLI to watch for CSS changes and spit out the optimised + minified .css file when I make changes to the source. This seems to work as expected.
I’m building / dev-ing in a src
tree and the Tailwind CLI outputs crunched CSS into a dist
tree in the Textpattern theme format. My Textpattern pages & forms are also being built in the src
tree, and what I’m looking for is a watcher to monitor for non-Tailwind changes in src
and then parse it through an HTML + CSS minifier on its way to dist
. I then have Transmit watching the dist
tree and uploading to the web-side theme scaffold. I can then import from the browser and – shazam – it should work.
There is etc_flat
that can cover the last part of the above, but if I can get 90% of the way there without a plugin with a bodge or two for the last part, I’d prefer that. No shade on Oleg, I’m just front loading the work for lazy efficiency reasons.
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
I’m developing a theme …
You’ve made me curious already…
I’ll clarify a little.
Ah, right. Got it. I use etc_flat
for the local development part and it works well. That said, I don’t compile the entire them folder, just the assets, so my theme dev folder has following structure:
/assets
/forms
/pages
/src
/styles
and then compile css, js, fonts, icons, ui imagery from the /src
subfolders to corresponding folders in the /assets
folder.
I use parceljs for that with the parcel reporter static files copy for assets that need copying but not compiling such as webfonts, icons, img files, etc.
If you’re using Codekit (I remember you were considering it), you can do that using the Hooks feature and have it trigger a regular cli cp/rsync/whatever action on compile. You can define what should trigger the hook, and it gives you a couple of path variables to help you work with a src and build folder.
EDIT: If you’re working with Tailwind, my guess is that your working process is a little different. The css will probably change fairly infrequently, but you’ll be changing your forms and templates often as you do your formatting with tailwind classes.
PS: I get how treeshaking works on sites built with static site generators because it can act on an entire pre-built html site, but can you get Tailwind to scan your Textpattern page templates and forms to reduce the weight of your css?
TXP Builders – finely-crafted code, design and txp
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
jakob wrote #340024:
I use
etc_flat
for the local development part and it works well. That said, I don’t compile the entire them folder, just the assets, so my theme dev folder has following structure:
/assets...
I’m close to that, but a level or so ‘up’ (somewhat WIP while I get the minifying sorted):
/sites
/example.com
/dist
/theme-name
/1.2.3
/forms
[all the forms in their respective dirs, minified]
LICENCE
manifest.json
/pages
[all the pages, minified]
/styles
[compiled Tailwind, minified].css
[compiled non-Tailwind, minified].css
/scripts
[all the watch & build scripts]
/src
/theme-name
/1.2.3
/forms
[all the forms in their respective dirs]
LICENCE
manifest.json
/pages
[all the pages]
/styles
/tailwind
[Tailwind CSS directives]
[non-Tailwind styles]
I use parceljs for that with the parcel reporter static files copy for assets that need copying but not compiling such as webfonts, icons, img files, etc.
I keep hearing ParcelJS mentioned, that may well be a thing I can use to do some of the lifting. I’ll have a look with fresh eyes over the weekend – thank you!
If you’re using Codekit (I remember you were considering it), you can do that using the Hooks feature and have it trigger a regular cli cp/rsync/whatever action on compile. You can define what should trigger the hook, and it gives you a couple of path variables to help you work with a src and build folder.
I went back & forth with Codekit, largely because of your advice & feedback. I was slightly at odds with my mischmasch of compile-from-source zealotry, maintainable local systems (i.e. not keen to pollute a file system with sorts of package managers and versions of such-and-such), and tentative acceptance of software subscriptions. If I’d bought a CodeKit sub for a year this time last year, I estimate I would have used it perhaps once or twice…then not renewed as I wasn’t using it, paradoxically. My brain is a bit funny sometimes.
I may well end up going with CodeKit if I can’t get what I want with non-package manager macOS stuff (and ParcelJS looks doable at first glance, for sure).
If it’s not an absolute horror show, I’ll aim to report back when (if) it’s all running smoothly.
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
It’s probably at odds with your package manager abstinence, but parcel does that for certain asset types. Where I’ve needed minification on its own, maybe esbuild (it has a watch mode).
That said, I’ve not ever considered minifying the textpattern page templates and forms. I expect Textpattern/Textile still adds in whitespace when producing the page output. You can compress / de-whitespace the resulting compiled html with pat_speeder, but I’m sure you already know about that.
I went back & forth with Codekit…
I used it for many years when I couldn’t get to grips with other bundlers. I tried parcel and vite a few years later and managed to get something more or less workable going. Since then my codekit sub has also lapsed, though there are times when I need to go back to it for an old site.
I don’t quite get where Transmit comes into the equation, but I’m sure you have your reasons.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
jakob wrote #340026:
I don’t quite get where Transmit comes into the equation, but I’m sure you have your reasons.
Directory sync. Local to remote.
help.panic.com/transmit/transmit5/synchronize/
I don’t run Textpattern locally, I prefer to use it on web-side hosting. It’s an extra step in the process, and has some disadvantages, but having my source files in a private repo and some Transmit shortcuts makes setting up another Mac pretty straightforward. I have a stack of 3x Mac minis and switch between them with client work, computing tasks, and other stuff. I might be working on one Mac for one task, then it has something that chews up a lot of processor power for a long time, and I can seamlessly switch to another Mac with the same setup (but more headroom on the CPU, for example).
I have been caught out before with macOS package managers and not documenting what I did on a given Mac, and when that gets retired (or kamikaze’s out of service), I was scratching my head on what to do with the new build, which package manager was handling which package, and so on. Too many bodges on my part, and lesson learned. The setup time for a ‘vanilla’ Mac is a few hours now, rather than most of a day previously. Copious notes seem to help.
Very much a strong opinion weakly held, however. I’m asking here because there are no doubt many superior ways to do what I’m doing – and I am most appreciative of your perspective.
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
Ah, your setup, and your need to switch ad hoc, is more high-powered than mine.
I have a desk-bound work computer and a home laptop, so I do switch between computers when developing, but not as often as you. I experiment a lot directly in the code editor, so committing to git all the time isn’t really appropriate. Instead, both computers have the same file structure + user name. At the end of an active work cycle, I’ll export the db and tar up the folder to a cloud folder (I have slimtar
aliased to tar timestamped without the modules or cache folders, which keeps the file size down) and unpack and reimport the db on the other machine and can pick up where I left off. Not really automated but only a couple of steps at each end.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
jakob wrote #340028:
Ah, your setup, and your need to switch ad hoc, is more high-powered than mine.
My generalist approach to client work means I’m involved in a bunch of unpredictable stuff, often involving heavy disk I/O and CPU. The Mac minis I used are M2 tier, and they tend to bottleneck pretty quickly when heavy stuff is underway, especially the disk. I use Nova as my IDE, and commit a lot so I can roll back easily when stuff breaks or I have a bright idea that I want to try. In my case, Nova sometimes struggles when the disk is redline’d; I can easily reproduce a 10-second file delete operation for a small text file which should be instant…no idea why it gets in a knot, but it’s enough of a pain when I’m binning a few files and each one takes 10 seconds or more to go. Commits and pushes are fine, it seems to be deletes that throw a fit.
At the end of an active work cycle, I’ll export the db and tar up the folder to a cloud folder (I have
slimtar
aliased to tar timestamped without the modules or cache folders, which keeps the file size down) and unpack and reimport the db on the other machine and can pick up where I left off. Not really automated but only a couple of steps at each end.
You could have a look at PHPBU if you ever want to automate some or all of the process. I’ve used this in anger for years, and it’s really good. Easily scriptable & scheduled.
Offline
Re: Monitor a directory for changes; run a shell script (macOS)
What about inotify? Is there a port for macOS via homebrew or something?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline