apostrophecms / apostrophe-monitor

Monitors and restarts an Apostrophe app when your code, templates, etc. change. Like nodemon but much faster because it takes advantage of how Apostrophe works.
8 stars 1 forks source link

Function that binds to chokidar `on` event for debug view perspective. #2

Closed ammein closed 4 years ago

ammein commented 5 years ago

I make an external function that extends from monitor-config.js for better log file changes using apos.utils.log. It is useful to debug or to watch which files are changes and also to make sure addIgnore works when restarting the site. This is extremely useful for me to see my site works perfectly and see the progress while restarting. I hope this would be beneficial too to other devs. For example :

// in /monitor-config.js
module.exports = {
    on : function(event , filename , apos){
        apos.utils.log(event , filename)
    }
}

If this PR agree to merge, could you publish to npm ? I would like to see an immediate effect and use it when update the package later 😄 . Also, if merged, I believe this should be documented in README too to let other devs know how to use it 😁

boutell commented 5 years ago

Hmm. I get why you want to do this but want to make sure we do it in a forwards-compatible way. Should it be only chokidar events? "on" is a very general term. Should it tie us to chokidar forever by making it part of the official developer interface? (I'd say we should avoid that.)

I think it might be more appropriate to just add support for verbose logging in monitor.js itself when APOS_MONITOR_LOG=1 is in the environment; when you see that env var, log stuff to console.debug, etc.

That doesn't tie us to a developer interface.

What do you think?

ammein commented 5 years ago

I think to emit on chokidar events is a good approach. But when I dive into the code. There are several if else statement that already done that filters only on specific module changes or added. Using apostrophe events or any kind of events tied but only filtered on specific changes or re-added would be extremely helpful.

I think I should tell you my specific use case on why I'm doing this is because my local development site is kept responding to change even I'm not saving my editor. I wanted to know, which files that are triggering changes without my consent. That is why I made a custom function that listens to file changes but NOT ALL. (Means exclude unnecessary files, only wanted to know my saved file changes only). Also, my local dev site is taking too long to restarting. By this solution, I could see file changes easily and avoid "Don't make me wait" kind of experience.

I hope you get the idea 😄

boutell commented 5 years ago

Sure. I think adding a simple "log" function in monitor.js that you call with anything that is interesting to log, with an if statement in it to check for an env var, would achieve this without creating a new developer interface that exposes chokidar forever as part of the API.

boutell commented 4 years ago

Going to close this because we decided it makes more sense to introduce a verbose logging option in apostrophe-monitor itself, so that we are not embracing chokidar forever by directly exposing it (leaky abstraction). But that PR for the verbose logging would be quite welcome. Thanks for contributing as always.