Introducing hunter, a CLI file watcher for Haxe

Having your development tools rebuild your project automatically when a source file changes can be very convenient. Especially when you’re trying to ensure that everything looks just right, and you’re making a lot of tiny little tweaks, which require a short feedback loop.

Today, I’m releasing the first version a new CLI utility for Haxe developers that I’m calling hunter. This tool runs in Haxe’s interpreter using the haxelib run hunter command, and it simply watches one or more directories for changes. When a change gets detected, it automatically runs any command line tool that you specify. For instance, you might watch your src directory for changes to .hx code, and then compile your project in response.

Here’s an example command that will rebuild a Haxe project when files in the src directory change:

haxelib run hunter "haxe compile.hxml" src

The first argument passed to hunter is the command to run (be sure to wrap it in quotes or escape the spaces if you need to include arguments), and it is followed by a separate argument for each directory to watch for file changes. There are a few optional arguments available too, like --ignoreDotFiles and --interval, which you can learn about in the README.

Or maybe you’re using OpenFL instead. Luckily, any CLI command is supported by hunter:

haxelib run hunter "lime build html5" src

The hunter utility is built using the file system watchers implemented in the excellent haxe-files library.

My reason for building hunter is to help transition Lime and OpenFL away from requiring Node.js for certain functionality, like the -watch option. Ideally, any Haxe developer (not only those using OpenFL and Lime) should be able to use haxelib run for common development tasks like this, without requiring a separate runtime like Node.js, Python, etc. to be installed on a their system. It’s the same reason why I created Snake Server, which provides a simple HTTP server for testing JS and HTML content locally. I’m hoping that the next major version of Lime will be able to switch to these new CLI utilities that run in the Haxe interpreter instead of Node.js. It will result in a smaller Lime bundle to download, and it will enrich the Haxe ecosystem with new tools that everyone can use.

To install hunter, run the following command:

haxelib install hunter

The hunter source code is available on GitHub. PRs with bug fixes are certainly welcome!

I hope that the Haxe community finds hunter to be useful for rebuilding projects when files change. If you like hunter (or my other utilities, like snake-server), please consider a monthly donation towards my open source contributions on my GitHub Sponsors page. Thank you!

About Josh Tynjala

Josh Tynjala is a frontend software developer, open source contributor, karaoke enthusiast, and he likes bowler hats. Josh develops Feathers UI, a user interface component library for creative apps, and he is a member of the OpenFL leadership team. One of his side projects is Logic.ly, a digital logic circuit simulator for education. You should follow Josh on Mastodon.

Leave a Reply

Your email address will not be published. Required fields are marked *