Advertisement
Guest User

HTML5 Boilerplate buildscript

a guest
Jan 18th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 45.26 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <!DOCTYPE project>
  3. <project name="Boilerplate Build" default="build" basedir="../"> <!-- one back since we're in build/ -->
  4.  
  5.  
  6.     <!-- Load in Ant-Contrib to give us access to some very useful tasks! -->
  7.     <!-- the .jar file is located in the tools directory -->
  8.     <taskdef resource="net/sf/antcontrib/antlib.xml">
  9.         <classpath>
  10.             <pathelement location="${basedir}/build/tools/ant-contrib-1.0b3.jar"/>
  11.         </classpath>
  12.     </taskdef>
  13.    
  14.     <!-- load shell environment -->
  15.     <property environment="ENV" />
  16.  
  17.     <!-- load property files -->
  18.     <property file="build/config/project.properties"/>
  19.     <property file="build/config/default.properties"/>
  20.  
  21.     <!-- merge the stylesheet properties -->
  22.     <var name="stylesheet-files" value="${file.default.stylesheets}, ${file.stylesheets}"/>
  23.  
  24.     <!-- merge the pages properties -->
  25.     <var name="page-files" value="${file.pages}, ${file.pages.default.include}"/>
  26.  
  27.     <!-- Test for Ant Version Delete this task and all instances of overwrite='no' if you can't upgrade to 1.8.2-->
  28.     <fail message="All features of the build script require Ant version 1.8.2. Please upgrade to 1.8.2 or remove all instances of 'overwrite=no' (and this fail task) from the build script to continue">
  29.         <condition>
  30.             <not>
  31.                 <contains string="${ant.version}" substring="1.8.2"/>
  32.             </not>
  33.         </condition>
  34.     </fail>
  35.  
  36.     <!--
  37.    *************************************************
  38.    * BASE TARGETS                                  *
  39.    *************************************************
  40.    -->
  41.     <target name="basics">
  42.     <if>
  43.         <equals arg1="${env}" arg2="dev"/>
  44.         <then>
  45.             <!-- Build a dev environment -->
  46.             <echo message="Building a Development Environment..."/>
  47.             <antcall target="-basics.dev"/>
  48.         </then>
  49.  
  50.         <elseif>
  51.             <equals arg1="${env}" arg2="test"/>
  52.             <then>
  53.                 <!-- Build a test environment -->
  54.                 <echo message="Building a Test Environment..."/>
  55.                 <antcall target="-basics.test"/>
  56.             </then>
  57.         </elseif>
  58.  
  59.         <else>
  60.             <!-- Build a production environment -->
  61.             <echo message="Building a Production Environment..."/>
  62.             <antcall target="-basics.production"/>
  63.         </else>
  64.     </if>
  65.     </target>
  66.  
  67.  
  68.     <target name="text">
  69.     <if>
  70.         <equals arg1="${env}" arg2="dev"/>
  71.         <then>
  72.             <!-- Build a dev environment -->
  73.             <echo message="Building a Development Environment..."/>
  74.             <antcall target="-text.dev"/>
  75.         </then>
  76.  
  77.         <elseif>
  78.             <equals arg1="${env}" arg2="test"/>
  79.             <then>
  80.                 <!-- Build a test environment -->
  81.                 <echo message="Building a Test Environment..."/>
  82.                 <antcall target="-text.test"/>
  83.             </then>
  84.         </elseif>
  85.  
  86.         <else>
  87.             <!-- Build a production environment -->
  88.             <echo message="Building a Production Environment..."/>
  89.             <antcall target="-text.production"/>
  90.         </else>
  91.     </if>
  92.     <antcall target="-imgcopy"/>
  93.     </target>
  94.  
  95.  
  96.     <target name="buildkit">
  97.     <if>
  98.         <equals arg1="${env}" arg2="dev"/>
  99.         <then>
  100.             <!-- Build a dev environment -->
  101.             <echo message="Building a Development Environment..."/>
  102.             <antcall target="-buildkit.dev"/>
  103.         </then>
  104.  
  105.         <elseif>
  106.             <equals arg1="${env}" arg2="test"/>
  107.             <then>
  108.                 <!-- Build a test environment -->
  109.                 <echo message="Building a Test Environment..."/>
  110.                 <antcall target="-buildkit.test"/>
  111.             </then>
  112.         </elseif>
  113.  
  114.         <else>
  115.             <!-- Build a production environment -->
  116.             <echo message="Building a Production Environment..."/>
  117.             <antcall target="-buildkit.production"/>
  118.         </else>
  119.     </if>
  120.     </target>
  121.  
  122.  
  123.     <target name="build">
  124.     <if>
  125.         <equals arg1="${env}" arg2="dev"/>
  126.         <then>
  127.             <!-- Build a dev environment -->
  128.             <echo message="Building a Development Environment..."/>
  129.             <antcall target="-build.dev" />
  130.         </then>
  131.  
  132.         <elseif>
  133.             <equals arg1="${env}" arg2="test"/>
  134.             <then>
  135.                 <!-- Build a test environment -->
  136.                 <echo message="Building a Test Environment..."/>
  137.                 <antcall target="-build.test" />
  138.             </then>
  139.         </elseif>
  140.  
  141.         <else>
  142.             <!-- Build a production environment -->
  143.             <echo message="Building a Production Environment..."/>
  144.             <antcall target="-build.production" />
  145.         </else>
  146.     </if>
  147.     </target>
  148.  
  149.  
  150.     <target name="minify">
  151.     <if>
  152.         <equals arg1="${env}" arg2="dev"/>
  153.         <then>
  154.             <!-- Build a dev environment -->
  155.             <echo message="Building a Development Environment..."/>
  156.             <antcall target="-minify.dev"/>
  157.         </then>
  158.  
  159.         <elseif>
  160.             <equals arg1="${env}" arg2="test"/>
  161.             <then>
  162.                 <!-- Build a test environment -->
  163.                 <echo message="Building a Test Environment..."/>
  164.                 <antcall target="-minify.test"/>
  165.             </then>
  166.         </elseif>
  167.  
  168.         <else>
  169.             <!-- Build a production environment -->
  170.             <echo message="Building a Production Environment..."/>
  171.             <antcall target="-minify.production"/>
  172.         </else>
  173.     </if>
  174.     </target>
  175.  
  176.     <target name="clean" depends="-clean"/>
  177.    
  178.    
  179.    
  180.     <!-- JSLint target, run separately -->
  181.     <target name="jslint">
  182.       <apply dir="${dir.source}/${dir.js}" executable="java" parallel="false" failonerror="true">
  183.             <fileset dir="./${dir.source}/">
  184.         <include name="**/${dir.js}/*.js"/>
  185.         <exclude name="**/*.min.js"/>
  186.         <exclude name="**/${dir.js.libs}/"/>
  187.         <exclude name="**/${dir.publish}/"/>
  188.           </fileset>
  189.             <arg value="-jar" />
  190.             <arg path="./${dir.build.tools}/${tool.rhino}" />
  191.             <arg path="./${dir.build.tools}/${tool.jslint}" />
  192.             <srcfile/>
  193.             <arg value="${tool.jslint.opts}" />
  194.         </apply>        
  195.         <echo>JSLint Successful</echo>
  196.     </target>    
  197.  
  198.  
  199.     <!-- JSHint target, run separately -->
  200.     <target name="jshint">
  201.       <apply dir="${dir.source}/${dir.js}" executable="java" parallel="false" failonerror="true">
  202.             <fileset dir="./${dir.source}/">
  203.         <include name="**/${dir.js}/*.js"/>
  204.         <exclude name="**/*.min.js"/>
  205.         <exclude name="**/${dir.js.libs}/"/>
  206.         <exclude name="**/${dir.publish}/"/>
  207.           </fileset>
  208.             <arg value="-jar" />
  209.             <arg path="./${dir.build.tools}/${tool.rhino}" />
  210.             <arg path="./${dir.build.tools}/${tool.jshint}" />
  211.             <srcfile/>
  212.             <arg value="${tool.jshint.opts}" />
  213.         </apply>        
  214.         <echo>JSHint Successful</echo>
  215.     </target>    
  216.        
  217.     <!-- CSSLint target, run separately -->
  218.     <target name="csslint">
  219.         <apply dir="${dir.source}/${dir.css}" executable="java" parallel="false" failonerror="true">
  220.             <fileset dir="./${dir.source}/">
  221.                 <include name="**/${dir.css}/*.css"/>
  222.                 <exclude name="**/*.min.css"/>
  223.                 <exclude name="**/${dir.publish}/"/>
  224.             </fileset>
  225.             <arg value="-jar" />
  226.             <arg path="./${dir.build.tools}/${tool.rhino}" />
  227.             <arg path="./${dir.build.tools}/${tool.csslint}" />
  228.             <srcfile/>
  229.             <arg value="${tool.csslint.opts}" />
  230.         </apply>
  231.         <echo>CSSLint Successful</echo>
  232.     </target>
  233.    
  234.     <!--
  235.    *************************************************
  236.    * BUILD TARGETS                                 *
  237.    *************************************************
  238.    -->
  239.  
  240.     <!-- Target: basics -->
  241.     <target name="-basics.dev"
  242.            depends="-rev,
  243.                     -copy"/>
  244.  
  245.     <target name="-basics.test"
  246.            depends="-rev,
  247.                     -usemin,
  248.                     -js.all.minify,
  249.                     -js.main.concat,
  250.                     -js.mylibs.concat,
  251.                     -js.scripts.concat,
  252.                     -css,
  253.                     -manifest,
  254.                     -copy"/>
  255.  
  256.     <target name="-basics.production"
  257.            depends="-rev,
  258.                     -usemin,
  259.                     -js.all.minify,
  260.                     -js.main.concat,
  261.                     -js.mylibs.concat,
  262.                     -js.scripts.concat,
  263.                     -css,
  264.                     -manifest,
  265.                     -copy"/>
  266.  
  267.     <!-- Target: text -->
  268.     <target name="-text.dev"
  269.            depends="-rev,
  270.                     -copy"/>
  271.  
  272.     <target name="-text.test"
  273.            depends="-rev,
  274.                     -usemin,
  275.                     -js.all.minify,
  276.                     -js.main.concat,
  277.                     -js.mylibs.concat,
  278.                     -js.scripts.concat,
  279.                     -css,
  280.                     -manifest,
  281.                     -htmlclean,
  282.                     -copy"/>
  283.  
  284.     <target name="-text.production"
  285.            depends="-rev,
  286.                     -usemin,
  287.                     -js.all.minify,
  288.                     -js.main.concat,
  289.                     -js.mylibs.concat,
  290.                     -js.scripts.concat,
  291.                     -css,
  292.                     -manifest,
  293.                     -htmlclean,
  294.                     -copy"/>
  295.  
  296.     <!-- Target: buildkit -->
  297.     <target name="-buildkit.dev"
  298.            depends="-rev,
  299.                     -imagespng,
  300.                     -imagesjpg,
  301.                     -copy"/>
  302.  
  303.     <target name="-buildkit.test"
  304.            depends="-rev,
  305.                     -usemin,
  306.                     -js.all.minify,
  307.                     -js.main.concat,
  308.                     -js.mylibs.concat,
  309.                     -js.scripts.concat,
  310.                     -css,
  311.                     -manifest,
  312.                     -htmlbuildkit,
  313.                     -imagespng,
  314.                     -imagesjpg,
  315.                     -copy"/>
  316.  
  317.     <target name="-buildkit.production"
  318.            depends="-rev,
  319.                     -usemin,
  320.                     -js.all.minify,
  321.                     -js.main.concat,
  322.                     -js.mylibs.concat,
  323.                     -js.scripts.concat,
  324.                     -css,
  325.                     -manifest,
  326.                     -htmlbuildkit,
  327.                     -imagespng,
  328.                     -imagesjpg,
  329.                     -copy"/>
  330.  
  331.     <!-- Target: build -->
  332.     <target name="-build.dev"
  333.            depends="-rev,
  334.                     -imagespng,
  335.                     -imagesjpg,
  336.                     -copy"/>
  337.  
  338.     <target name="-build.test"
  339.            depends="-rev,
  340.                     -usemin,
  341.                     -js.all.minify,
  342.                     -js.main.concat,
  343.                     -js.mylibs.concat,
  344.                     -js.scripts.concat,
  345.                     -css,
  346.                     -manifest,
  347.                     -htmlclean,
  348.                     -imagespng,
  349.                     -imagesjpg,
  350.                     -copy"/>
  351.  
  352.     <target name="-build.production"
  353.            depends="-rev,
  354.                     -usemin,
  355.                     -js.all.minify,
  356.                     -js.main.concat,
  357.                     -js.mylibs.concat,
  358.                     -js.scripts.concat,
  359.                     -css,
  360.                     -manifest,
  361.                     -htmlclean,
  362.                     -imagespng,
  363.                     -imagesjpg,
  364.                     -copy"/>
  365.  
  366.     <!-- Target: minify -->
  367.     <target name="-minify.dev"
  368.            depends="-rev,
  369.                     -imagespng,
  370.                     -imagesjpg,
  371.                     -copy"/>
  372.  
  373.     <target name="-minify.test"
  374.            depends="-rev,
  375.                     -usemin,
  376.                     -js.all.minify,
  377.                     -js.main.concat,
  378.                     -js.mylibs.concat,
  379.                     -js.scripts.concat,
  380.                     -css,
  381.                     -manifest,
  382.                     -htmlcompress,
  383.                     -imagespng,
  384.                     -imagesjpg,
  385.                     -copy"/>
  386.  
  387.     <target name="-minify.production"
  388.            depends="-rev,
  389.                     -usemin,
  390.                     -js.all.minify,
  391.                     -js.main.concat,
  392.                     -js.mylibs.concat,
  393.                     -js.scripts.concat,
  394.                     -css,
  395.                     -manifest,
  396.                     -htmlcompress,
  397.                     -imagespng,
  398.                     -imagesjpg,
  399.                     -copy"/>
  400.  
  401.     <!--
  402.    *************************************************
  403.    * FUNCTION TARGETS                              *
  404.    *************************************************
  405.    -->
  406.        
  407.     <target name="-clean" description="(PRIVATE) Wipe the previous build (Deletes the dir.publish directory">
  408.     <!-- This is a private target -->        
  409.         <echo message="Cleaning up previous build directory..."/>
  410.         <delete dir="./${dir.intermediate}/"/>
  411.         <delete dir="./${dir.publish}/"/>
  412.     </target>
  413.    
  414.    
  415.     <target name="-rev" description="(PRIVATE) Increase the current build number by one and set build date">
  416.     <!-- This is a private target -->
  417.    
  418.         <echo message="====================================================================="/>
  419.         <echo message="Welcome to the HTML5 Boilerplate Build Script!"/>
  420.         <echo message=" "/>
  421.         <echo message="We're going to get your site all ship-shape and ready for prime time."/>
  422.         <echo message=" "/>
  423.         <echo message="This should take somewhere between 15 seconds and a few minutes,"/>
  424.         <echo message="mostly depending on how many images we're going to compress."/>
  425.         <echo message=" "/>
  426.         <echo message="Feel free to come back or stay here and follow along."/>
  427.         <echo message="====================================================================="/>
  428.         <echo message=" "/>
  429.         <echo message=" "/>
  430.    
  431.     </target>
  432.    
  433.     <target name="-mkdirs">
  434.       <if>
  435.           <or>
  436.             <equals arg1="${dir.publish}" arg2="."/>            
  437.             <equals arg1="${dir.publish}" arg2=".."/>                      
  438.             <equals arg1="${dir.publish}" arg2="/"/>                      
  439.             <equals arg1="${dir.publish}" arg2="./"/>                      
  440.             <equals arg1="${dir.publish}" arg2="../"/>                      
  441.           </or>
  442.           <then>
  443.             <fail message="Your dir.publish folder is set to ${dir.publish} which could delete your entire site or worse. Change it in project.properties"/>      
  444.           </then>
  445.           <else>
  446.             <echo message="Creating directory structure... ${dir.publish}"/>
  447.  
  448.             <mkdir dir="${dir.intermediate}"/>
  449.             <copy todir="${dir.intermediate}" includeEmptyDirs="true">
  450.                 <fileset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}">
  451.                     <type type="dir"/>
  452.                 </fileset>
  453.             </copy>
  454.               <mkdir dir="${dir.publish}"/>
  455.               <copy todir="${dir.publish}" includeEmptyDirs="true">
  456.                   <fileset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}">
  457.                       <type type="dir"/>
  458.                   </fileset>
  459.               </copy>                      
  460.           </else>
  461.       </if>                  
  462.     </target>
  463.    
  464.     <target name="-copy" depends="-mkdirs">
  465.     <!-- This is a private target -->
  466.    
  467.         <echo message="Copying over new files..."/>
  468.  
  469.         <copy todir="./${dir.publish}">
  470.             <fileset dir="${dir.source}/" excludes="${file.default.exclude}, ${file.exclude}">
  471.                 <!-- exclude files that are superseded by optimized versions with different names -->
  472.                 <!-- this is not strictly necessary, but it avoids putting unreferenced files into your server -->
  473.                 <exclude name="${dir.js}/**/*.js"/>
  474.                 <exclude name="${dir.css}/**/*.css"/>
  475.                 <exclude name="${file.manifest}"/>
  476.             </fileset>
  477.         </copy>
  478.        
  479.         <echo message="A copy of all non-dev files are now in: ./${dir.publish}."/>
  480.     </target>
  481.    
  482.     <!-- JAVASCRIPT -->
  483.     <target name="-js.main.concat" depends="-js.all.minify" description="(PRIVATE) Concatenates the JS files in dir.js">
  484.         <echo message="Concatenating Main JS scripts..."/>
  485.         <!-- overwrite=no here means not to overwrite if the target is newer than the sources -->
  486.         <concat destfile="./${dir.intermediate}/${dir.js}/scripts-concat.js" overwrite="no">
  487.             <fileset dir="./${dir.intermediate}/">
  488.                 <include name="${dir.js.main}/plugins.js"/>
  489.                 <include name="${dir.js.main}/script.js"/>
  490.             </fileset>      
  491.         </concat>
  492.     </target>
  493.    
  494.     <target name="-js.mylibs.concat" depends="-js.all.minify" description="(PRIVATE) Concatenates the JS files in dir.js.mylibs">
  495.         <mkdir dir="./${dir.intermediate}/${dir.js.mylibs}"/>
  496.  
  497.         <echo message="Concatenating JS libraries"/>
  498.         <!-- overwrite=no here means not to overwrite if the target is newer than the sources -->
  499.         <concat destfile="./${dir.intermediate}/${dir.js}/mylibs-concat.js" overwrite="no">
  500.             <fileset dir="./${dir.intermediate}/${dir.js.mylibs}/"
  501.                includes="**/*.js"
  502.                excludes="${file.js.bypass}"/>                
  503.                  
  504.         </concat>
  505.     </target>
  506.    
  507.    
  508.     <target name="-js.scripts.concat" depends="-js.main.concat,-js.mylibs.concat" if="build.concat.scripts">
  509.         <echo message="Concatenating library file with main script file"/>
  510.         <!-- overwrite=no here means not to overwrite if the target is newer than the sources -->
  511.         <concat destfile="./${dir.intermediate}/${dir.js}/scripts-concat.min.js" overwrite="no">
  512.             <fileset dir="./${dir.intermediate}/${dir.js}/">
  513.                 <include name="mylibs-concat.js"/>
  514.                 <include name="scripts-concat.js"/>
  515.             </fileset>      
  516.         </concat>
  517.  
  518.         <checksum file="${dir.intermediate}/${dir.js}/scripts-concat.min.js" algorithm="sha" property="scripts.sha" />
  519.         <if>
  520.             <isset property="gae.js_dir" />
  521.             <then>
  522.                 <property name="scripts.js" value="${gae.js_dir}/${scripts.sha}.js" />
  523.             </then>
  524.             <else>
  525.                 <property name="scripts.js" value="${dir.js}/${scripts.sha}.js" />
  526.             </else>
  527.         </if>
  528.         <copy file="${dir.intermediate}/${dir.js}/scripts-concat.min.js" tofile="${dir.publish}/${dir.js}/${scripts.sha}.js" />
  529.     </target>
  530.    
  531.    
  532.     <target name="-js.all.minify" depends="-mkdirs" description="(PRIVATE) Minifies the scripts.js files created by js.scripts.concat">
  533.         <echo message="Minifying scripts"/>
  534.         <copy todir="${dir.intermediate}/">
  535.             <fileset dir="${dir.source}/" includes="${dir.js}/**/*.min.js"  />
  536.         </copy>
  537.         <apply executable="java" parallel="false">
  538.             <fileset dir="${dir.source}/" >
  539.                 <include name="${dir.js}/**/*.js"/>
  540.                 <exclude name="${dir.js}/**/*.min.js"/>
  541.             </fileset>
  542.             <arg line="-jar"/>
  543.             <arg path="./${dir.build.tools}/${tool.yuicompressor}"/>
  544.             <srcfile/>
  545.             <arg line="--line-break"/>
  546.             <arg line="4000"/>
  547.             <arg line="-o"/>
  548.             <mapper type="glob" from="*.js" to="${basedir}/${dir.intermediate}/*.js"/>
  549.             <targetfile/>
  550.         </apply>
  551.  
  552.         <!-- at this point all js files are minified with their original names -->
  553.  
  554.         <copy todir="${dir.publish}/">
  555.           <fileset dir="${dir.intermediate}/">
  556.               <include name="${dir.js}/**/*.js"/>
  557.               <exclude name="${dir.js.mylibs}/**/*.js"/>
  558.               <exclude name="${dir.js}/scripts-concat.js"/>
  559.               <exclude name="${dir.js}/mylibs-concat.js"/>
  560.               <exclude name="${dir.js}/scripts-concat.min.js"/>
  561.               <exclude name="${dir.js}/plugins.js"/>
  562.               <exclude name="${dir.js}/script.js"/>
  563.           </fileset>                                  
  564.         </copy>
  565.         <copy todir="${dir.publish}/${dir.js.mylibs}/">
  566.             <fileset dir="${dir.source}/${dir.js.mylibs}/"
  567.            includes="${file.js.bypass}"/>          
  568.         </copy>
  569.     </target>
  570.    
  571.    
  572.     <!-- HTML -->
  573.     <target name="-usemin" depends="-js.scripts.concat,-css" description="(PRIVATE) Replaces references to non-minified scripts">
  574.         <echo message="Switching to minified js files..."/>
  575.  
  576.         <!-- Changes to style.css or scripts.js mean that the html must be updated, and it will be.
  577.             Unfortunately, the html we want to update may not have the tags we want to replace(because it was updated before).
  578.             This outofdate check ensures that the html files have the markers for us to replace. -->
  579.         <outofdate property="needhtmlrefresh">
  580.             <sourcefiles>
  581.                 <fileset dir="${dir.publish}" includes="${style.css}, ${scripts.js}"/>
  582.             </sourcefiles>
  583.             <targetfiles>
  584.                 <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  585.             </targetfiles>
  586.         </outofdate>
  587.  
  588.         <!-- force the files to be overwritten with older copies from source if needhtmlrefresh is set -->
  589.         <copy todir="${dir.intermediate}" overwrite="${needhtmlrefresh}">
  590.             <fileset dir="${dir.source}" includes="${page-files}"/>
  591.         </copy>
  592.  
  593.         <!-- switch from a regular jquery to minified -->
  594.         <replaceregexp match="jquery-(\d|\d(\.\d)+)\.js" replace="jquery-\1.min.js" flags="g">
  595.             <fileset dir="./${dir.intermediate}" includes="${page-files}"/>
  596.         </replaceregexp>
  597.         <!-- switch any google CDN reference to minified -->
  598.         <replaceregexp match="(\d|\d(\.\d)+)\/jquery\.js" replace="\1/jquery.min.js" flags="g">
  599.             <fileset dir="./${dir.intermediate}" includes="${page-files}"/>
  600.         </replaceregexp>    
  601.  
  602.         <echo>Kill off those versioning flags: ?v=2</echo>
  603.         <replaceregexp match='\?v=\d+">' replace='">' flags="g">
  604.             <fileset dir="./${dir.intermediate}" includes="${page-files}"/>
  605.         </replaceregexp>
  606.        
  607.         <echo>Remove favicon.ico reference if it is pointing to the root</echo>
  608.         <replaceregexp match="&lt;link rel=[&quot;']shortcut icon[&quot;'] href=[&quot;']/favicon\.ico[&quot;']&gt;" replace="">
  609.             <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  610.         </replaceregexp>
  611.         <!-- we maintain the apple-touch-icon reference for Android 2.2   www.ravelrumba.com/blog/android-apple-touch-icon
  612.        <replace token="&lt;link rel=&quot;apple-touch-icon&quot; href=&quot;/apple-touch-icon.png&quot;>" value="">
  613.            <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  614.        </replace>
  615.        -->
  616.  
  617.         <echo message="Update the HTML to reference our concatenated script file: ${scripts.js}"/>
  618.         <!-- style.css replacement handled as a replacetoken above -->
  619.         <replaceregexp match="&lt;!-- scripts concatenated [\d\w\s\W]*?!-- end ((scripts)|(concatenated and minified scripts))--&gt;" replace="&lt;script defer src='${scripts.js}\'&gt;&lt;/script&gt;" flags="m">
  620.             <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  621.         </replaceregexp>
  622.         <!--[! use comments like this one to avoid having them get minified -->
  623.  
  624.         <echo message="Updating the HTML with the new css filename: ${style.css}"/>
  625.  
  626.         <replaceregexp match="&lt;!-- CSS concatenated [\d\w\s\W]*?!-- end CSS--&gt;" replace="&lt;link rel='stylesheet' href='${style.css}'&gt;" flags="m">
  627.             <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  628.         </replaceregexp>
  629.  
  630.     </target>
  631.    
  632.    
  633.     <target name="-manifest" depends="-usemin">
  634.         <if>
  635.             <isset property="file.manifest" />
  636.             <then>
  637.                 <echo message="copying a fresh ${dir.build}/config/${file.manifest} to /${dir.intermediate}"/>
  638.  
  639.                 <delete file="${dir.intermediate}/${file.manifest}"/>
  640.                 <copy file="${dir.build}/config/${file.manifest}" tofile="${dir.intermediate}/${file.manifest}" />
  641.                
  642.                 <echo message="manifest creation" />
  643.  
  644.                 <!-- update version -->
  645.                 <echo message="Updating the site.manifest version date to today, current time"/>
  646.                 <tstamp>
  647.                     <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss"/>
  648.                 </tstamp>
  649.                 <replaceregexp match="# version .+" replace="# version ${TODAY}" file="${dir.intermediate}/${file.manifest}"/>
  650.  
  651.                 <!-- add html files -->
  652.                 <echo message="Updating the site.manifest with html files: ${page-files}"/>
  653.                 <for list="${page-files}" param="file" delimiter="," trim="true">
  654.                     <sequential>
  655.                         <replaceregexp match="# html files" replace="# html files${line.separator}@{file}" file="${dir.intermediate}/${file.manifest}" />
  656.                     </sequential>
  657.                 </for>
  658.                
  659.                 <!-- add stylesheet files -->
  660.                 <echo message="Updating the site.manifest with the new css filename: ${style.css}"/>
  661.                 <replace token="# css files" value="# css files${line.separator}${style.css}" file="${dir.intermediate}/${file.manifest}" />
  662.  
  663.                 <!-- add javascript files -->
  664.                 <echo message="Updating the site.manifest with the new js filename: ${scripts.js}"/>
  665.                 <for param="file">
  666.                     <path>
  667.                         <fileset dir="./${dir.intermediate}/${dir.js.mylibs}/"
  668.                            includes="${file.js.bypass}" />
  669.                     </path>
  670.                     <sequential>
  671.                         <basename property="filename.@{file}" file="@{file}" />
  672.                         <replaceregexp match="# js files" replace="# js files${line.separator}${dir.js.mylibs}/${filename.@{file}}" file="${dir.intermediate}/${file.manifest}" />
  673.                     </sequential>
  674.                 </for>
  675.                 <for param="file">
  676.                     <path>
  677.                         <fileset dir="./${dir.intermediate}/${dir.js.libs}/"
  678.                            includes="*.min.js"/>
  679.                     </path>
  680.                     <sequential>
  681.                         <basename property="filename.@{file}" file="@{file}" />
  682.                         <replaceregexp match="# js files" replace="# js files${line.separator}${dir.js.libs}/${filename.@{file}}" file="${dir.intermediate}/${file.manifest}" />
  683.                     </sequential>
  684.                 </for>
  685.                 <replace token="# js files" value="# js files${line.separator}${scripts.js}" file="${dir.intermediate}/${file.manifest}" />
  686.                
  687.                 <echo message="copying ${file.manifest} to /${dir.publish}"/>
  688.                 <copy file="${dir.intermediate}/${file.manifest}" tofile="${dir.publish}/${file.manifest}" />
  689.                
  690.                 <echo>Add manifest attribute to HTML: </echo>
  691.                 <replaceregexp match="&lt;html (.*?)>\s*?&lt;!--&lt;!\[endif" replace='&lt;html \1 manifest="${file.manifest}"> &lt;!--&lt;![endif' flags="g">
  692.                     <fileset dir="./${dir.intermediate}" includes="${page-files}"/>
  693.                 </replaceregexp>
  694.                
  695.             </then>
  696.             <else>
  697.                 <echo message="no manifest.appcache generated!" />
  698.             </else>
  699.         </if>
  700.     </target>
  701.    
  702.     <target name="-htmlclean" depends="-usemin">
  703.         <echo message="Run htmlcompressor on the HTML"/>
  704.         <echo message=" - maintaining whitespace"/>
  705.         <echo message=" - removing html comments"/>
  706.         <echo message=" - compressing inline style/script tag contents"/>
  707.         <apply executable="java" parallel="false" dest="./${dir.publish}/" >
  708.             <fileset dir="./${dir.intermediate}/" includes="${page-files}"/>
  709.             <arg value="-jar"/>
  710.             <arg path="./${dir.build.tools}/${tool.htmlcompressor}"/>
  711.             <arg line="--preserve-multi-spaces"/>
  712.             <arg line="--remove-quotes"/>
  713.             <arg line="--compress-js"/>
  714.             <arg line="--compress-css"/>
  715.             <arg line="--preserve-php"/>
  716.             <arg line="--preserve-ssi"/>
  717.             <srcfile/>
  718.             <arg value="-o"/>
  719.             <mapper type="glob" from="*" to="../${dir.publish}/*"/>
  720.             <targetfile/>
  721.         </apply>
  722.     </target>
  723.    
  724.    
  725.     <target name="-htmlbuildkit" depends="-usemin">
  726.         <echo message="Run htmlcompressor on the HTML"/>
  727.         <echo message=" - maintaining whitespace"/>
  728.         <echo message=" - retain html comments"/>
  729.         <echo message=" - compressing inline style/script tag contents"/>
  730.         <apply executable="java" parallel="false" dest="./${dir.publish}/" >
  731.             <fileset dir="./${dir.intermediate}/" includes="${page-files}"/>
  732.             <arg value="-jar"/>
  733.             <arg path="./${dir.build.tools}/${tool.htmlcompressor}"/>
  734.             <arg value="--preserve-comments"/>
  735.             <arg line="--preserve-multi-spaces"/>
  736.             <arg line="--compress-js"/>
  737.             <arg line="--compress-css"/>
  738.             <arg line="--preserve-php"/>
  739.             <arg line="--preserve-ssi"/>
  740.             <srcfile/>
  741.             <arg value="-o"/>
  742.             <mapper type="glob" from="*" to="../${dir.publish}/*"/>
  743.             <targetfile/>
  744.         </apply>
  745.     </target>
  746.    
  747.    
  748.     <target name="-htmlcompress" depends="-usemin">
  749.         <echo message="Run htmlcompressor on the HTML"/>
  750.         <echo message=" - removing unnecessary whitespace"/>
  751.         <echo message=" - removing html comments"/>
  752.         <echo message=" - compressing inline style/script tag contents"/>
  753.         <apply executable="java" parallel="false" dest="./${dir.publish}/" >
  754.             <fileset dir="./${dir.intermediate}/" includes="${page-files}"/>
  755.             <arg value="-jar"/>
  756.             <arg path="./${dir.build.tools}/${tool.htmlcompressor}"/>
  757.             <arg line="--remove-quotes"/>
  758.             <arg line="--compress-js"/>
  759.             <arg line="--compress-css"/>
  760.             <arg line="--preserve-php"/>
  761.             <arg line="--preserve-ssi"/>
  762.             <srcfile/>
  763.             <arg value="-o"/>
  764.             <mapper type="glob" from="*" to="../${dir.publish}/*"/>
  765.             <targetfile/>
  766.         </apply>
  767.     </target>
  768.  
  769.  
  770.     <!-- CSS -->
  771.  
  772.     <target name="-css-remove-concatenated-stylesheets">
  773.             <echo>Removing ${css_file} from html</echo>
  774.             <replaceregexp match="&lt;link.+href=&quot;.*${css_file}&quot;.*&gt;" replace="  ">
  775.                 <fileset dir="${dir.intermediate}" includes="${page-files}"/>
  776.             </replaceregexp>      
  777.     </target>
  778.        
  779.  
  780.     <target name="css-split" description="turns style.css into multiple files @imported together">
  781.         <copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}.temp"/>
  782.        
  783.         <replaceregexp file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp"
  784.               match=".*"
  785.               replace="/* remove me */" flags="s" />
  786.    
  787.         <loadfile property="root" srcfile="${dir.source}/${dir.css}/${file.root.stylesheet}"/>
  788.         <var name="curr.buffer" value=""/>
  789.    
  790.         <for delimiter="${line.separator}" param="currline" list="${root}">
  791.             <sequential>
  792.                 <!-- does this line contain an h5bp-import? -->
  793.                 <propertyregex property="export.name" input="@{currline}" regexp="^.*==\|== +(.*) +==+$" select="\1" casesensitive="true" override="true" />
  794.                 <if>
  795.                     <isset property="export.name"/>
  796.                     <then>
  797.                         <propertyregex property="export.name" input="${export.name}" regexp=" " replace="." global="true" override="true" />
  798.                         <var name="export.name" value="${export.name}.css"/>          
  799.                    
  800.                         <if>
  801.                             <isset property="curr.file"/>
  802.                             <then>
  803.                                 <!-- create curr.file -->
  804.                                 <copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${curr.file}" overwrite="true"/>
  805.                                 <!-- write the curr.buffer into the curr.file -->
  806.                                 <replaceregexp file="${dir.source}/${dir.css}/${curr.file}"
  807.                                       match=".*"
  808.                                       replace="${curr.buffer}" flags="s" />
  809.                                
  810.                                 <var name="curr.buffer" value=""/>
  811.                                 <var name="curr.file" unset="true"/>
  812.                             </then>
  813.                         </if>
  814.                         <var name="curr.file" value="${export.name}"/>
  815.                         <var name="export.name" unset="true"/>
  816.  
  817.                         <!-- insert import line into new root -->
  818.                         <replace file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" token="/* remove me */" value="@import url(${curr.file});${line.separator}/* remove me */"/>
  819.                     </then>
  820.                 </if>
  821.                 <var name="curr.buffer" value="${curr.buffer}@{currline}${line.separator}" />                                        
  822.             </sequential>
  823.         </for>
  824.         <!-- one more time to write out the last file -->
  825.         <if>
  826.             <isset property="curr.file"/>
  827.             <then>
  828.                 <!-- create curr.file -->
  829.                 <copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${curr.file}" overwrite="true"/>
  830.                 <!-- write the curr.buffer into the curr.file -->
  831.                 <replaceregexp file="${dir.source}/${dir.css}/${curr.file}"
  832.                       match=".*"
  833.                       replace="${curr.buffer}" flags="s" />
  834.                
  835.                 <var name="curr.buffer" value=""/>
  836.                 <var name="curr.file" unset="true"/>
  837.             </then>
  838.         </if>
  839.         <replace file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" token="/* remove me */" value="${curr.buffer}"/>
  840.         <copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}.orig" overwrite="false"/>
  841.         <move file="${dir.source}/${dir.css}/${file.root.stylesheet}.temp" tofile="${dir.source}/${dir.css}/${file.root.stylesheet}" overwrite="false"/>
  842.     </target>
  843.    
  844.     <target name="-css" depends="-mkdirs" description="Concatenates and Minifies any stylesheets listed in the file.stylesheets property">
  845.         <echo message="Concatenating any @imports..."/>
  846.  
  847.         <!-- copy source file to intermediate directory -->
  848.         <copy file="${dir.source}/${dir.css}/${file.root.stylesheet}" tofile="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"/>
  849.  
  850.         <!-- replace imports with h5bp-import tags (part 1) this one wraps @media types -->
  851.         <replaceregexp file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
  852.                        match="^@import\s+(?:url\s*\(\s*['&quot;]?|['&quot;])((?!http:|https:|ftp:)[^&quot;^'^\s]+)(?:['&quot;]?\s*\)|['&quot;])\s*([\w\s,\-]*);.*$"
  853.                       replace="@media \2{ /* h5bp-import: \1 */ }" byline="true" />
  854.        
  855.         <!-- replace imports with h5bp-import tags (part 2) -->
  856.         <replaceregexp file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
  857.                       match="^@media \{ (/\* .* \*/) \}" replace="\1" byline="true" />
  858.  
  859.         <!-- copy skeleton to concat file -->
  860.         <copy file="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"
  861.              tofile="${dir.intermediate}/${dir.css}/style-concat.css" overwrite="true"/>
  862.  
  863.         <!-- load the file into a property -->
  864.         <loadfile property="imports" srcfile="${dir.intermediate}/${dir.css}/${file.root.stylesheet}"/>
  865.  
  866.         <var name="concat-files" value="${file.root.stylesheet}"/>
  867.  
  868.         <!-- go over the file line by line -->
  869.         <for delimiter="${line.separator}" param="import" list="${imports}">
  870.             <sequential>
  871.                 <!-- does this line contain an h5bp-import? -->
  872.                 <propertyregex property="file.name" input="@{import}" regexp="/\* h5bp-import: (.*) \*/" select="\1" casesensitive="true" override="true" />
  873.  
  874.                 <if>
  875.                     <isset property="file.name"/>
  876.                     <then>
  877.                         <var name="concat-files" value="${file.name},${concat-files}"/>
  878.  
  879.                         <!-- load the file into a variable -->
  880.                         <loadfile property="file.contents" srcFile="${dir.source}/${dir.css}/${file.name}"/>
  881.  
  882.                         <!-- pop that file into the concatenated output file -->
  883.                         <replace file="${dir.intermediate}/${dir.css}/style-concat.css" token="/* h5bp-import: ${file.name} */" value="${file.contents}"/>
  884.  
  885.                         <var name="file.contents" unset="true"/>
  886.                     </then>
  887.                 </if>
  888.             </sequential>
  889.         </for>
  890.         <echo message="Minifying css..."/>
  891.        
  892.         <apply executable="java" parallel="false">
  893.             <fileset dir="${dir.intermediate}/${dir.css}/" includes="style-concat.css"/>
  894.             <arg line="-jar"/>
  895.             <arg path="${dir.build.tools}/${tool.yuicompressor}"/>
  896.             <srcfile/>
  897.             <arg line="-o"/>
  898.             <mapper type="merge" to="${basedir}/${dir.intermediate}/${dir.css}/style-concat.min.css"/>
  899.             <targetfile/>
  900.         </apply>
  901.  
  902.         <checksum file="${dir.intermediate}/${dir.css}/style-concat.min.css" algorithm="sha" property="css.sha" />
  903.         <if>
  904.             <isset property="gae.css_dir" />
  905.             <then>
  906.                 <property name="style.css" value="${gae.css_dir}/${css.sha}.css" />
  907.             </then>
  908.             <else>
  909.                 <property name="style.css" value="${dir.css}/${css.sha}.css" />
  910.             </else>
  911.         </if>
  912.         <copy file="${dir.intermediate}/${dir.css}/style-concat.min.css" tofile="${dir.publish}/${dir.css}/${css.sha}.css" />
  913.  
  914.         <echo message="Minifying any unconcatenated css files..."/>
  915.  
  916.         <apply executable="java" parallel="false">
  917.             <fileset dir="${dir.source}/${dir.css}/" excludes="${concat-files}" includes="**/*.css"/>
  918.             <arg line="-jar"/>
  919.             <arg path="${dir.build.tools}/${tool.yuicompressor}"/>
  920.             <srcfile/>
  921.             <arg line="-o"/>
  922.             <mapper type="glob" from="*.css" to="${basedir}/${dir.publish}/${dir.css}/*.css"/>
  923.             <targetfile/>
  924.         </apply>
  925.         <foreach list="${file.stylesheets}" param="css_file" target="-css-remove-concatenated-stylesheets" />        
  926.     </target>
  927.    
  928.    
  929.     <!-- IMAGES -->
  930.     <target name="-imagespng" depends="-mkdirs" description="(PRIVATE) Optimizes .png images using optipng">
  931.         <echo message="Optimizing images..."/>
  932.         <echo message="This part might take a while. But everything else is already done."/>
  933.         <echo message=" "/>
  934.        
  935.        
  936.         <echo message="First, we run optipng on the .png files..."/>
  937.        
  938.         <!-- osfamily=unix is actually true on OS X as well -->
  939.         <!-- On *nix's and OS X, check for optipng and give a helpful message if it's not installed -->
  940.         <if>
  941.             <and>
  942.                 <os family="unix" />
  943.                 <available file="optipng" filepath="${ENV.PATH}" />
  944.             </and>
  945.             <then>
  946.                 <!-- work around https://sourceforge.net/tracker/?func=detail&aid=2671422&group_id=151404&atid=780916 -->
  947.                 <delete>
  948.                     <fileset dir="./${dir.publish}/${dir.images}/">
  949.                         <include name="**/*.png"/>
  950.                     </fileset>
  951.                 </delete>
  952.                 <apply executable="optipng" dest="./${dir.publish}/${dir.images}/" osfamily="unix">
  953.                     <fileset dir="./${dir.source}/${dir.images}/" includes="**/*.png"  excludes="${images.bypass}, ${images.default.bypass}"/>
  954.                     <arg value="-quiet"/>
  955.                     <arg value="-o7"/>
  956.                     <arg value="-out"/>
  957.                     <targetfile/>
  958.                     <srcfile/>
  959.                     <mapper type="identity"/>
  960.                 </apply>
  961.             </then>
  962.             <elseif>
  963.                 <os family="unix" />
  964.                 <then>
  965.                     <echo message="*** optipng NOT INSTALLED. SKIPPING OPTIMIZATION OF PNGs." />
  966.                     <echo message="*** Install optipng to enable png optimization." />
  967.                     <echo message="*** For instructions see 'Dependencies' at: http://html5boilerplate.com/docs/#Build-script#dependencies" />
  968.                 </then>
  969.             </elseif>
  970.         </if>
  971.  
  972.         <!-- work around https://sourceforge.net/tracker/?func=detail&aid=2671422&group_id=151404&atid=780916 -->
  973.         <delete>
  974.             <fileset dir="./${dir.publish}/${dir.images}/">
  975.                 <include name="**/*.png"/>
  976.             </fileset>
  977.         </delete>
  978.         <apply executable="${basedir}/${dir.build.tools}/optipng-0.6.4-exe/optipng.exe" dest="./${dir.publish}/${dir.images}/" osfamily="windows">
  979.             <fileset dir="./${dir.source}/${dir.images}/" includes="**/*.png"  excludes="${images.bypass}, ${images.default.bypass}"/>
  980.             <arg value="-quiet"/>
  981.             <arg value="-o7"/>
  982.             <arg value="-out"/>
  983.             <targetfile/>
  984.             <srcfile/>
  985.             <mapper type="identity"/>
  986.         </apply>
  987.     </target>
  988.  
  989.  
  990.     <target name="-imagesjpg" depends="-mkdirs" description="(PRIVATE) Optimizes .jpg images using jpegtan">
  991.         <echo message="Now, we clean up those jpgs..."/>
  992.  
  993.         <if>
  994.             <equals arg1="${images.strip.metadata}" arg2="true"/>
  995.             <then>
  996.                 <var name="strip-meta-tags" value="none"/>
  997.             </then>
  998.             <else>
  999.                 <var name="strip-meta-tags" value="all"/>
  1000.             </else>
  1001.         </if>
  1002.  
  1003.         <!-- On *nix's and OS X, check for jpegtran and give a helpful message if it's not installed -->
  1004.         <if>
  1005.             <and>
  1006.                 <os family="unix" />
  1007.                 <available file="jpegtran" filepath="${ENV.PATH}" />
  1008.             </and>
  1009.             <then>
  1010.                 <apply executable="jpegtran" dest="./${dir.publish}/${dir.images}" osfamily="unix">
  1011.                     <fileset dir="${dir.source}/${dir.images}" includes="**/*.jpg" excludes="${images.bypass}, ${images.default.bypass}"/>
  1012.                     <arg value="-copy"/>
  1013.                     <arg value="${strip-meta-tags}"/>
  1014.                     <arg value="-optimize"/>
  1015.                     <arg value="-outfile"/>
  1016.                     <targetfile/>
  1017.                     <srcfile/>
  1018.                     <mapper type="identity"/>
  1019.                     <!-- you may want to flag optimized images. If so, do it here. Otherwise change this to type="identity" -->
  1020.                     <!--<mapper type="glob" from="*.jpg" to="*.jpg"/>-->
  1021.                 </apply>
  1022.             </then>
  1023.             <elseif>
  1024.                 <os family="unix" />
  1025.                 <then>
  1026.                     <echo message="*** jpegtran NOT INSTALLED. SKIPPING OPTIMIZATION OF JPEGs." />
  1027.                     <echo message="*** Install jpegtran to enable jpeg optimization." />
  1028.                     <echo message="*** For instructions see 'Dependencies' at: http://html5boilerplate.com/docs/#Build-script#dependencies" />
  1029.                 </then>
  1030.             </elseif>
  1031.         </if>
  1032.  
  1033.         <apply executable="${basedir}/${dir.build.tools}/jpegtran.exe" dest="./${dir.publish}/${dir.images}" osfamily="windows">
  1034.             <fileset dir="${dir.source}/${dir.images}" includes="**/*.jpg"  excludes="${images.bypass}, ${images.default.bypass}"/>
  1035.             <arg value="-copy"/>
  1036.             <arg value="${strip-meta-tags}"/>
  1037.             <arg value="-optimize"/>
  1038.             <arg value="-outfile"/>
  1039.             <targetfile/>
  1040.             <srcfile/>
  1041.             <mapper type="identity"/>
  1042.             <!-- you may want to flag optimized images. If so, do it here. Otherwise change this to type="identity" -->
  1043.             <!--<mapper type="glob" from="*.jpg" to="*.jpg"/>-->
  1044.         </apply>
  1045.     </target>
  1046.  
  1047.  
  1048.     <target name="-imgcopy" depends="-mkdirs">
  1049.         <echo message="Copying over the unmodified images."/>
  1050.  
  1051.         <copy todir="./${dir.publish}/${dir.images}">
  1052.             <fileset dir="${dir.source}/${dir.images}"  includes="**/*.jpg, **/*.png"/>
  1053.         </copy>
  1054.     </target>
  1055.    
  1056. </project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement