MeanwhileInHell MeanwhileInHell - 1 year ago 69
Javascript Question

Running a single command on multiple files using Ant

I'm trying to compile a bunch of handlebars templates into a single compiled file using ant. I have a number of folders that each contain about 4 templates each and I want to compile these all into one file. With folders like:

folder01
|- templates
|- f1_01.handlebars
|- f1_02.handlebars
|- f1_03.handlebars
|- f1_04.handlebars
folder02
|- templates
|- f2_01.handlebars
|- f2_02.handlebars
|- f2_03.handlebars
|- f2_04.handlebars
build.xml


I essentially want to run the command:

handlebars **/templates/*.handlebars -f compiled-templates.js


I have tried the following but it only seems to include 1 file in the output js file.

<macrodef name="handlebars">
<attribute name="target"/>
<sequential>
<apply executable="${handlebars}" failonerror="false">
<fileset dir="." includes="**/templates/">
<include name="*.handlebars"/>
</fileset>
<arg value="-f compiled-templates.js"/>
</apply>
</sequential>
</macrodef>


Also, strangely, the output file starts with a space character, which I can't seem to get rid of. Any help would be greatly appreciated.

Answer Source

I ended up using a <concat> task, to create one file out of all the templates, and running the executable once on that file.

<concat destfile="all.handlebars" append="true">
    <fileset dir="." includes="**/templates/">
        <include name="*.handlebars"/>
    </fileset>
</concat>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download