How to run macro at OpenFl project before OpenFl parses assets?

Hello everybody,

I have a project with localization files kept in “.properties” format.
I have a macro which converts them to Json and applies ZLIB compression to the final json.

Project xml snippet:

<haxeflag name="--macro" value="macros.BuildMacro.compileLocales()"/>

<assets path="assets/locales/common.zjson" rename="locales/common" generate="false" preload="true"/>

The question is how to organize the compilation process to compile locales (run macro) before OpenFl detects that compiled .zjson files are not yet created?

Error:Could not find asset path "assets/locales/common.zjson"
Error: (Command exited with an error code) 1
Error:Compilation failed

Thanks.

Perhaps you could try writing a script using HXP to do this?

haxelib install hxp

script.hx

package;

import hxp.*;

class Script extends hxp.Script
{
	private var samples:Array<String>;

	public function new()
	{
		super();

		if (command == "update" || command == "build" || command == "test")
		{
			macros.BuildMacro.compileLocales();
		}

		System.runCommand("", "openfl", [ command ].concat(commandArgs));
	}
}

Usage:

hxp path/to/script.hx test neko
hxp test neko (same directory)

I’m open to adding a change to the Lime command-line tools to execute an HXP script as part of the build if someone wanted to chat on Discord about implementing that