2012-03-12 93 views
3

我试图使用ant将一堆手柄模板编译成单个编译文件。我有许多文件夹,每个文件夹都包含大约4个模板,我想将这些文件全部编译成一个文件。有了这样的文件夹:使用Ant在多个文件上运行单个命令

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 

我基本上是要运行的命令:

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

我曾尝试以下,但它似乎只在输出中包含js文件1个文件。

<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> 

此外,奇怪的是,输出文件以一个空格字符开头,我似乎无法摆脱。任何帮助将不胜感激。

回答

-2

我结束了使用<concat>任务,从所有模板中创建一个文件,并在该文件上运行一次可执行文件。

<concat destfile="all.handlebars" append="true"> 
    <fileset dir="." includes="**/templates/"> 
     <include name="*.handlebars"/> 
    </fileset> 
</concat> 
+0

你不觉得这个回答有错吗?因为如果你连接所有的模板,那么它将被视为单个模板文件。当你对它们进行适当的预编译时,它会创建一个单独的文件,但是在这个文件中它有适当的模板间隔。现在在你的情况下,在单个输出文件中的模板之间不会分离。因此Handlebars.runtime.js将无法找到它需要的确切模板文件。 – anit 2013-11-26 11:30:33

+0

这确实是该问题的正确答案,并且所有模板都能够正确使用并保持使用至今,因此不需要进行分离。你可以请你删除你的downvote,或者至少等待你的回答“你不觉得这个答案是错误的”问题。你有没有打算在断言其正确性之前测试这个解决方案?从使用的语言来看,这看起来令人怀疑。 – MeanwhileInHell 2013-11-26 11:51:15

+0

我还注意到,您没有提供对问题的“正确”答案,或提出了其他任何建议。 – MeanwhileInHell 2013-11-26 11:58:52

1

尝试:

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

代替:

... 
<arg value="-f compiled-templates.js"/> 
... 
+0

谢谢,这工作。 – MeanwhileInHell 2012-03-14 10:25:56

+1

接受答案或upvote,如果我建议的解决方案为你工作!? – Rebse 2012-03-14 19:27:27

+0

@NomNomNom在这种情况下接受帮助你的答案。 – 2012-03-14 20:05:57

0

使用<script>任务,你可以嵌入JavaScript或Groovy代码,做迭代工作。调用一些短脚本来帮助解决这些问题是一种很好的做法,因为它们通常比棘手的XML循环条件符号更具表现力。

2

在stackoverflow上搜索了很多,更重要的是,阅读文档我想出了这个解决方案的工作原理。

<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> 
+0

所以基本上这将执行节点./webclient/build/node_modules/handlebars/bin/handlebars <模板列表> -f webclient/app/templates/handlebars.templates.js – anit 2013-11-26 15:27:08