wplib / wplib-box

The Best Local Dev Server for WordPress Developers
https://wplib.github.io/box-docs/
MIT License
209 stars 24 forks source link

Implement "File Watchers" #76

Open mikeschinkel opened 8 years ago

mikeschinkel commented 8 years ago

I'd like to discuss how we could potentially add "File Watchers" to so we could orchestrate tools to run in the box to post-process code using Gulp, Grunt, etc. and even user-specified scripts.

One thing I'd really like to be able to do is run an optimization script and a script to increment the value of a class constant in each PHP file so we could reliably tell that its code has been updated to allow us to optimally allow us to run "activation" and "preparation" code, but only when likely needed.

My thoughts are we could have a JSON file that defines the directories, file types and/or files to watch and then have a way to specify what script to run in the JSON but with some logical default based on script location and script name and folder name.

Here are some related links:

Let's discuss.

clubdeuce commented 8 years ago

@mikeschinkel https://github.com/tartley/rerun2/blob/master/rerun

clubdeuce commented 8 years ago

Adding the inotify-tools package.

clubdeuce commented 8 years ago

@mikeschinkel To implement this, we will need a script that will load all files from a specified directory and execute each when a file changes.

This specified directory will have to be one that is shared between the host and guest.

mikeschinkel commented 8 years ago

@clubdeuce I propose /vagrant/scripts/watchers/.

clubdeuce commented 8 years ago

@mikeschinkel And should the files be bash scripts? PHP? Are we going to support multiple types?

mikeschinkel commented 8 years ago

@clubdeuce We discussed this. Remember when I asked if they could be version 7.0 of PHP?

I mentioned that it should be anything with shebang directive, but you could also expand that and can certain types explicitly by extension?

We could explicitly run .php, .rb and .sh but files with no extensions would be assumed to have a shebang directive?

mikeschinkel commented 8 years ago

@clubdeuce One thing though, they should log all output to a file so people could debug their scripts that were not working.

mikeschinkel commented 8 years ago

@clubdeuce As discussed via call today, just implement it so that your inotify-tools script calls /vagrant/scripts/watchers/on-file-action.sh and pass the results that inotify-tools generates as a change on the command line and inside the script merely echo that value, then we can close this ticket.

I have created another ticket #97 where we can add the php, ruby, python and bash support.

mikeschinkel commented 8 years ago

I recently learned about Facebook's Watchman from a webinar about HHVM & Hack. It makes me wonder why they created a tool if inotify-tools is sufficient?

So in case we decide to revisit this at some point I'm going to go ahead and document what I found while googling on the topic

mikeschinkel commented 8 years ago

@clubdeuce I have been trying to get this to work but no dice. Can you verify that it is working in 0.10.9?

mikeschinkel commented 8 years ago

@clubdeuce I think I figured this out. I will be making some changes to the repo.

mikeschinkel commented 8 years ago

@clubdeuce OR maybe not.

So it seems that inotifywait does not work on mounted drives: :-(

This puts a big kink into the works for some of my plans. We should discuss the ramifications of this and what the best workaround might be.

mikeschinkel commented 8 years ago

@clubdeuce Issues #147 and #150 are blockers for me on this issue.

mikeschinkel commented 8 years ago

@clubdeuce See lines 8 through 24 which allow the command box enable-file-watchers to work but that I really would rather be pre-provisioned: