Running one command for multiple files with Ant
I am trying to compile a bunch of descriptor templates into one compiled file using ant. I have several folders, each containing about 4 templates, and I want to compile them 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 really want to run the command:
handlebars **/templates/*.handlebars -f compiled-templates.js
I tried the following but it seems only 1 file is 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, oddly enough, the output file starts with a space character, which I cannot get rid of. Any help would be greatly appreciated.
+3
source to share
4 answers
After searching stackoverflow many times and more importantly reading the docs, I came up with this solution that 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>
+2
source to share