ANT: Collate files


/ Published in: Other
Save to your folder(s)

Simple file concatenation target using the concat task. The to and from directories are set in properties at the top. The first concat clears the file and writes a JS comment with the date on it, the second uses both a filelist (where you write filenames manually) and a fileset (where you just write a filter) to select the files to include.


Copy this code and paste it in your HTML
  1. <property
  2. name = "dir.from"
  3. value = "/PATH/TO/SOURCE/DIRECTORY/"
  4. />
  5. <property
  6. name = "dir.to"
  7. value = "/PATH/TO/TARGET/DIRECTORY/"
  8. />
  9.  
  10.  
  11. <target
  12. name = "collateJS"
  13. description = "collects JS files"
  14. >
  15. <!-- creates a timestamp - useful when someone reads the file without access to ant -->
  16. <tstamp>
  17. <format
  18. property = "generated"
  19. pattern = "yyyy-MM-dd HH:mm:ss"
  20. locale = "en,UK"
  21. />
  22. </tstamp>
  23.  
  24. <!-- clears file and puts a JS style comment on top -->
  25. <concat
  26. destfile = "${dir.to}/concat.js"
  27. append = "false"><![CDATA[//generated by ant task collateJS ${generated}
  28.  
  29. ]]></concat>
  30.  
  31. <!-- does the concatenating -->
  32. <concat
  33. destfile = "${dir.to}/concat.js"
  34. append = "true">
  35.  
  36. <!-- list individual files manually -->
  37. <filelist
  38. dir = "${dir.from}"
  39. >
  40. <file name="file1.js" />
  41. <file name="file2.js" />
  42. </filelist>
  43.  
  44. <!-- creates a filter -->
  45. <fileset
  46. dir = "${dir.from}"
  47. >
  48. <include name="**/yes*"/>
  49. <exclude name="**/no*"/>
  50. </fileset>
  51. </concat>
  52. </target>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.