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!
Hello Mr. Tynjala, I am now preparing to develop a cross-platform game. I used to be an AS3 game developer, and now I am doing front-end development, such as using the React framework. I would like to ask you, when developing cross-platform games, mainly for iOS and Android, and may also involve Windows desktop, which one do you think is more suitable, Haxelib (haxe+flixel+openfl) or Phaser game framework? I hope you can help me analyze the advantages and disadvantages of the two. By the way, I have used Starling (AS3 version) before. Is there a Haxe version of Starling now?
As someone who has worked with Flash/AS3, I think that OpenFL/Haxe will be the most familiar to you. While we don’t have implementations of every API from Flash, we have a large portion covered, and it’s getting better with every version.
There is, in fact, a version of Starling for OpenFL. It is well-maintained, and generally, it is quickly updated with all of the fixes to the AS3 version that still occasionally get merged.
https://github.com/openfl/starling
https://lib.haxe.org/p/starling
One advantage of OpenFL and Haxe is that they can build native C++ apps for mobile and desktop, in addition to compiling JavaScript for the web. That’s probably going to result in better CPU performance than a JS/HTML library like Phaser, which uses interpreted JavaScript. Additionally, it means that you don’t need to rely on projects like Electron or Cordova to create native apps that use JS/HTML.
I haven’t personally used Phaser, so I can’t really offer direct comparisons beyond that.
Thank you for your answer, Mr. Tynjala. I am from China and there is some time difference. Once I am proficient in using OpenFL/Haxe framework, I hope to join your team and contribute to it. Thank you again for your reply and answer.
youre work on haxe stuff is so awesome and inspiring!!
Thanks so much!