2012-03-12 44 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

相關問題