lizh06 / fabricate

Automatically exported from code.google.com/p/fabricate
0 stars 0 forks source link

Watch to auto-build #50

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be great to have WAF automatically execute the steps required when 
files change.

This may allow something like SASS --watch which saves a lot of time.

The watch should allow to specify a target target so that only that is built 
automatically.

Original issue reported on code.google.com by wer...@beroux.com on 9 Sep 2013 at 11:51

GoogleCodeExporter commented 9 years ago
[Watchdog](https://github.com/gorakhargosh/watchdog) seems to help a lot on 
that.

Here is a script which does that so it should be easy to incorporate it in 
fabricate:

    import sys
    import time
    from watchdog.observers import Observer
    from watchdog.tricks import ShellCommandTrick

    if __name__ == __main__:
        event_handler = ShellCommandTrick(shell_command='python build.py', wait_for_process=True)
        observer = Observer()
        observer.schedule(event_handler, '.', recursive=True)
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()

It has a possible issue, when you touch a file it'll be recorded as a CREATE 
followed right after by a MODIFY event. There should probably be a buffer of a 
few milliseconds. Possibly the files could be filtered to include only some of 
them but that's more optional for now.

Original comment by wer...@beroux.com on 10 Sep 2013 at 11:52