Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 281
MeanwhileInHell Avatar asked May 22 '26 00:05

MeanwhileInHell


2 Answers

After searching a lot on stackoverflow and, more importantly, reading the docs i came up with this solution which works.

<echo level="info" message="Pre Compiling templates" />
<apply parallel="true" failonerror="true" executable="node">
  <arg value="${webclient.dir.build}/node_modules/handlebars/bin/handlebars" />
  <srcfile />
  <fileset dir="${webclient}/app/templates" includes="**/*.handlebars"/>
  <arg line="-f ${webclient}/app/templates/handlebars.templates.js -m -a" />
</apply>
like image 108
anit Avatar answered May 23 '26 12:05

anit


try :

...
<arg line="-f compiled-templates.js"/>
...

instead of :

...
<arg value="-f compiled-templates.js"/>
...
like image 27
Rebse Avatar answered May 23 '26 13:05

Rebse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!