Skip to content

Instantly share code, notes, and snippets.

Last active Jan 22, 2016
What would you like to do?
Ant Build-Script for my frontend projects
<?xml version="1.0" encoding="UTF-8" ?>
<project name="sunlix" default="usage" basedir=".">
Build file for
1. Compile related tasks
2. Deploy related tasks
3. Clean related tasks
How to use:
- set path variables for your local system
- go to the path where this build.xml file is located
on your computer
- run "ant deploy-preview" or "ant deploy-production"
to deploy files
- run "ant compile-preview" or "compile-production"
if you only want to compile with compass
<!-- modify these settings for your computer -->
<property name="compiler" value="${basedir}/../../compiler.jar" />
<!-- In particular, if you do not put a file extension on the executable, only ".EXE" files are looked for -->
<condition property="compass-exec" value="compass.bat" else="compass">
<os family="windows" />
<property name="sass" value="${basedir}/sass" />
<property name="assets" value="${basedir}/assets" />
<property name="assets.js" value="${assets}/js" />
<property name="assets.css" value="${assets}/css" />
<property name="assets.img" value="${assets}/img" />
<property name="assets.fonts" value="${assets}/fonts" />
<property name="stage-preview-path" value="${basedir}/../prev" />
<property name="stage-production-path" value="${basedir}/../prod" />
<!-- create a white-list of files that should be deployed -->
<fileset id="deployable" dir="${basedir}">
<exclude name="sass/" />
<include name="**/*.html" />
<include name="**/*.css" />
<include name="**/*.js" />
<patternset id="img">
<!-- image related -->
<include name="**/*.png" />
<include name="**/*.gif" />
<include name="**/*.jpg" />
<patternset id="fonts">
<!-- web font related -->
<include name="**/*.eot" />
<include name="**/*.otf" />
<include name="**/*.svg" />
<include name="**/*.ttf" />
<include name="**/*.woff" />
<include name="**/*.woff2" />
[Preperation] helper tasks
<target name="usage" description="Display usage information">
<echo message="Execute 'ant -projecthelp' for build file help." />
<echo message="Execute 'ant -help' for Ant help." />
<!-- get all javascript files in YAML framework directories -->
<target name="findAssets">
<copy todir="${assets.js}" flatten="true" overwrite="true">
<fileset dir="${sass}" includes="**/*.js" excludes="**/jquery.*.js" />
<copy todir="${assets.js}/libs" flatten="true" overwrite="true">
<fileset dir="${sass}" includes="**/jquery.*.js" />
<copy todir="${assets.img}" flatten="true" overwrite="true">
<fileset dir="${sass}">
<patternset refid="img" />
<copy todir="${assets.fonts}" flatten="true" overwrite="true">
<fileset dir="${sass}">
<patternset refid="fonts" />
<available file="${assets.js}/libs" type="dir" property="assets.js.libs" />
<!-- concat javascript libraries -->
<target name="concat" depends="findAssets" if="${assets.js.libs}" description="concatenate the javascript files">
<echo message="concatenate js libs..." />
<concat destfile="${assets.js}/jquery.libs.js">
<fileset dir="${assets.js}/libs" includes="*.js" />
[Compile] related tasks
<target name="compile" depends="compile-preview" description="set default compile settings" />
<target name="compile-preview" depends="concat" description="compile pretty for dev purposes, i.e. no compression, etc.">
<echo message="compiling with compass ..." />
<exec executable="${compass-exec}">
<arg line="compile -e development --force" />
<target name="compile-production" depends="concat" description="compile for production purposes, i.e. compressed, etc.">
<echo message="compiling with compass ..." />
<exec executable="${compass-exec}">
<arg line="compile -e production --force" />
<!-- define js compression -->
<!-- no advanced compilation due to no given externs for jquery -->
<apply executable="java" parallel="false" verbose="true" dest="${assets.js}">
<fileset dir="${assets.js}" includes="*.js" excludes="*.min.js" />
<arg line="-jar" />
<arg path="${compiler}" />
<arg value="--warning_level" />
<arg value="QUIET" />
<arg value="--js_output_file" />
<targetfile />
<arg value="--js" />
<mapper type="glob" from="*.js" to="*.min.js" />
[Deploy] related tasks
<target name="deploy" depends="deploy-preview" description="define default deployment behavior" />
<target name="deploy-production" depends="compile-production" description="deploy files to production">
<delete dir="${stage-production-path}" />
<copy todir="${stage-production-path}">
<fileset refid="deployable" />
<antcall target="clear-cache" />
<target name="deploy-preview" depends="compile-preview" description="deploy files to preview">
<delete dir="${stage-preview-path}" />
<copy todir="${stage-preview-path}">
<fileset refid="deployable" />
<antcall target="clear-cache" />
[Clean] related tasks
<target name="clear-cache" description="delete all compiled files">
<echo message="compass clean" />
<exec executable="${compass-exec}" output="${basedir}/../compass-output.txt">
<arg line="clean" />
<delete dir="${assets}" />
<target name="clear" depends="clear-cache" description="delete all deployed files">
<delete dir="${stage-preview-path}" />
<delete dir="${stage-production-path}" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment