Complex template processing

At compile time I need to generate two XML files which are very similar so I am wanting a way to use a single template to generate them both. Ideally I would like to generate one, then change a haxe define to have the other one output. So areas of my template would be excluded if that define was set. e.g.:

::if (DEFINE_SPECIALMODE)::
<product id="SPECIAL1"></product>
::end::

I know I can run lime a second time if I use a tag in my project XML like:
<haxeflag name="--cmd" value="lime build ./project.xml html5 -Dspecialmode -debug" /> but this adds a lot of compile time. Is there a way to just do the template processing without compiling the application? I would like to use it with native Lime or OpenFL compiling functions if I can.

I should mention that I tried using the project.xml by setting my define to a different value before each template tag but it didn’t seem to work as desired.

I think you can use the lime update command to skip compiling.

lime update html5

Here’s the description of this command:

Copy assets for the specified project and target

1 Like

This works, thanks Josh! I added this to my main project.xml.
<haxeflag name="--cmd" value="lime update ./project-special.xml html5 -debug -Dspecialmode" />

For the record, my normal compile takes 33 seconds. At first I ran that lime update command using the same project.xml and it ballooned the compile time up to a minute. I guess that despite not generating a new JavaScript file, it is still churning through all my code and libraries. So I created a new xml file (e.g. project-special.xml) containing my <template> tag, and it uses a stub Main class. That new xml file processes in 3 seconds, which is much better. I don’t like the additional almost-useless files in my project but it’s not a bad trade-off all the same.

Edit: I am now realising that I have to duplicate some of my defines from the main project.xml, which is now defeating my reason for starting down this road. I’ll report if I attain the ultimate solution! I might have to look at using hxp instead of xml.

The <include> tag may be helpful here to avoid duplicating things.

<include path="to/another/project.xml" />

Thanks, that solves the missing defines again but increases the compile time back to where it was. I still appreciate learning these tidbits! I think I will use this approach but have the tag commented out until I need to generate the new template.

Did you put the defines (and only the defines) into a third XML file that the first two XML files could both include? Or did you still have two files? With only two files, I’d expect it to be slower because more than just the defines would probably be shared.

Good thinking again! This works as expected, thanks again!
For the record, it is necessary for the included file to be a valid XML file with a project tag like so:

<?xml version="1.0" encoding="utf-8"?>
<project>
<set name="mydefine" value="someValue" />
</project>
1 Like

@Confidant, Thank you for following up with what you discovered. I love it when people do that, as it really adds a lot of value for others.

1 Like

Glad to do it. And you know what’s funny is I often come back here looking for help and I realise I already asked the same question a couple years ago, LOL.