Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
285 lines (249 sloc) 9.99 KB
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="DotnetMvcBoilerplate" default="build" basedir="../">
<!-- load shell environment -->
<property environment="ENV" />
<property file="build/config/project.properties"/>
<!-- load in Ant-Contrib to give us access to some very useful tasks! -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${tools.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- load in ant-dotnet to allow us to access MSBuild & NUnit -->
<taskdef resource="org/apache/ant/dotnet/antlib.xml">
<classpath>
<pathelement location="${tools.dir}/ant-dotnet/ant-dotnet-1.1.jar"/>
</classpath>
</taskdef>
<!--
full build process including everything required to validate the project and
getting the project ready for live environment.
-->
<target name="build" depends="-clean, -prepare, -compile, -unit-test, -compile-release, -copytointermediate, -css, -js, -publish, -tidy" />
<!--
removes some of the slower targets in order to test the build process.
-->
<target name="dev" depends="-clean, -prepare, -compile-release, -copytointermediate, -css, -js, -publish, -tidy" />
<!--
optimises all the images in the images directory.
-->
<target name="images" depends="-copyimages, -imagespng, -imageslosslessly" />
<!--
performs js linting on all the js.
-->
<target name="jslint">
<apply dir="${project.dir}/${js.dir}" executable="java" failonerror="true">
<fileset dir="${project.dir}/${js.dir}/">
<include name="*.js" />
<exclude name="/libs/*" />
</fileset>
<arg value="-jar" />
<arg path="${tool.rhino}" />
<arg path="${tool.jslint}" />
<srcfile />
<arg value="${tool.jslint.opts}" />
</apply>
</target>
<!--
deletes the artifacts generated from the previous build,
if there is one.
-->
<target name="-clean" >
<delete dir="${deploy.dir}" />
</target>
<!--
creates any directories that will be required during the
build process.
-->
<target name="-prepare">
<mkdir dir="${deploy.dir}" />
<mkdir dir="${test.reports.dir}" />
</target>
<!--
compiles the solution to ensure there are no errors before
we continue any further.
-->
<target name="-compile">
<nant buildfile="${nant.buildfile}">
<target name="compile" />
</nant>
</target>
<!--
Runs the unit tests copying the reports to the
deploy/test-reports directory.
-->
<target name="-unit-test">
<nant buildfile="${nant.buildfile}">
<target name="unit-test" />
</nant>
</target>
<!--
Compiles a release version of the solution, means
all the debug information will be removed.
-->
<target name="-compile-release">
<nant buildfile="${nant.buildfile}">
<target name="compile-release" />
</nant>
</target>
<!--
Copies the web project into an intermediate location
so we can modify files to speed up js, img & css loading
-->
<target name="-copytointermediate">
<copy todir="${intermediate.dir}">
<fileset dir="${project.dir}" />
</copy>
</target>
<target name="-css" depends="-css.min, -css.cache" />
<!--
Minifies the concatenated css file.
-->
<target name="-css.min">
<apply executable="java">
<fileset dir="${intermediate.dir}/${css.dir}" includes="${default.stylesheets.file}" />
<arg line="-jar"/>
<arg path="${tool.yuicompressor}"/>
<srcfile/>
<arg line="--type css"/>
<arg line="-o"/>
<mapper type="merge" to="${intermediate.dir}/${css.dir}/styles.min.css"/>
<targetfile/>
</apply>
</target>
<!--
Changes the name of the name of the concatenated css file to ensure that any
changes made to the stylesheet are presented to the user. The minified version
of the stylesheet is given a randomly generated new name and the <link> tag
to the main stylesheet file is changed to point at the renamed stylesheet.
-->
<target name="-css.cache">
<checksum file="${intermediate.dir}/${css.dir}/styles.min.css" algorithm="sha" property="css.fullsha" />
<propertyregex property="css.sha" input="${css.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="style.css" value="${css.dir}/${css.sha}.css" />
<copy file="${intermediate.dir}/${css.dir}/styles.min.css" tofile="${intermediate.dir}/${css.dir}/${css.sha}.css" />
<replaceregexp match="&lt;link(.+)href=['&quot;]?(.*)/${default.stylesheets.file}(?:\?.*)?['&quot;\s]?(.*/?&gt;)"
replace="&lt;link\1href='\2/${css.sha}.css'\3" flags="m">
<fileset dir="${intermediate.dir}" includes="${page-files}"/>
</replaceregexp>
<delete includeemptydirs="true">
<fileset dir="${intermediate.dir}/css" excludes="${css.sha}.css" />
</delete>
</target>
<target name="-js" depends="-js.concat, -js.min, -js.cache" />
<!--
Minifies the concatenateed javascript file.
-->
<target name="-js.min">
<apply executable="java">
<fileset dir="${intermediate.dir}/${js.dir}" includes="scripts.js"/>
<arg line="-jar"/>
<arg path="${tool.yuicompressor}"/>
<srcfile/>
<arg line="--type js"/>
<arg line="-o"/>
<mapper type="merge" to="${intermediate.dir}/${js.dir}/scripts.min.js"/>
<targetfile/>
</apply>
</target>
<!--
Concats all the js files that are inside the page files specified. These
js files are placed into a single file scripts.js file that is then copied
into a file with a cache buster name that is generated using the checksum.
-->
<target name="-js.concat">
<filelist id="file.root" dir="${intermediate.dir}" files="${page-files}" />
<apply executable="java" outputproperty="scripts.ordered">
<arg value="-cp"/>
<arg value="${tools.dir}/misc/" />
<arg value="ScriptsToConcat"/>
<first>
<filelist refid="file.root"/>
</first>
</apply>
<for param="js.file" list="${scripts.ordered}">
<sequential>
<concat destfile="${intermediate.dir}/${js.dir}/scripts.js" append="yes">
<filelist dir="${intermediate.dir}" files="@{js.file}"/>
</concat>
</sequential>
</for>
</target>
<!--
Changes the name of the main concatenated scripts file to ensure that any
the primary javascript file is never loaded from cached when a release is pushed.
The collection of javascript files in between the marker comments are removed and
replaced with the name of the new cache busting java script file.
-->
<target name="-js.cache">
<checksum file="${intermediate.dir}/${js.dir}/scripts.min.js" algorithm="sha" property="scripts.fullsha" />
<propertyregex property="scripts.sha" input="${scripts.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="scripts.js" value="${intermediate.dir}/${js.dir}/${scripts.sha}.js" />
<copy file="${intermediate.dir}/${js.dir}/scripts.min.js" tofile="${intermediate.dir}/${js.dir}/${scripts.sha}.js" />
<var name="matchRegex" value="&lt;!-- scripts concatenated [\d\w\s\W]*[\d\w\s\W]*&lt;!-- end ((scripts)|(concatenated and minified scripts))\s*--&gt;" />
<var name="replaceRegex" value="&lt;script async src='/${js.dir}/${scripts.sha}.js\'&gt;&lt;/script&gt;" />
<replaceregexp match="${matchRegex}" replace="${replaceRegex}" flags="m">
<fileset dir="${intermediate.dir}" includes="${page-files}"/>
</replaceregexp>
</target>
<!--
publishes the intermediate project into a working website.
-->
<target name="-publish">
<nant buildfile="${nant.buildfile}">
<target name="publish" />
</nant>
</target>
<!--
Removes directories and files that are no longer used.
-->
<target name="-tidy">
<delete dir="${intermediate.dir}" />
</target>
<!--
copies all the images into a seperate directory so they
can be manipulated.
-->
<target name="-copyimages">
<delete dir="${project.dir}/${optimised.images.dir}" />
<copy todir="${project.dir}/${optimised.images.dir}">
<fileset dir="${project.dir}/${images.dir}">
<exclude name="**/*.md" />
</fileset>
</copy>
</target>
<!--
Optimises all the PNG images to reduce their file size, this
may take a while depending on how many images there are.
-->
<target name="-imagespng">
<delete>
<fileset dir="${project.dir}/${optimised.images.dir}/">
<include name="**/*.png" />
</fileset>
</delete>
<apply executable="${tool.optipng}" dest="${project.dir}/${optimised.images.dir}/" osfamily="windows">
<fileset dir="${project.dir}/${images.dir}/" includes="**/*.png" excludes="${images.bypass}, ${images.default.bypass}"/>
<arg value="-quiet"/>
<arg value="-o7"/>
<arg value="-out"/>
<targetfile/>
<srcfile/>
<mapper type="identity"/>
</apply>
</target>
<!--
Optimises all the images with losslessly compression.
-->
<target name="-imageslosslessly">
<java jar="${tool.smushit}"
fork="true"
failonerror="false"
maxmemory="128m">
<arg value="-imageDir=${project.dir}/${optimised.images.dir}"/>
<arg value="-verbose=true" />
<arg value="-imgExtensions=png,jpeg,jpg" />
</java>
</target>
</project>