ant script for css/js compression

<?xml version="1.0" encoding="UTF-8"?>
<project name="yakbootstrap" default="yakbootstrap" basedir=".">
    <property name="yuicompressor.path" location="D:\tool\yuicompressor.jar"/>
    <property name="closure.path" location="D:\tool\compiler.jar"/>
    <property name="js.files" value="yakbootstrap.yakautocomplete.js, yakbootstrap.yaktag.js, yakbootstrap.yakpassportsearch.js,
    yakbootstrap.yakdatepicker.js, yakbootstrap.yaktimepicker.js, yakbootstrap.yakdatetimepicker.js,
    konami.js, run.js"/>
    <property name="yak.path" value="resources\yakbootstrap\" />
    
    <target name="js">
        <echo>Working...</echo>
        
        <mkdir dir="bin" />
        <concat destfile="bin\main.js" fixlastline="true">
            <fileset dir="dev\${yak.path}js" includes="yakbootstrap*.js" excludes="${js.files}" />
        </concat>
        <concat destfile="bin\main.js" fixlastline="true" append="true">
            <filelist dir="dev\${yak.path}js" files="${js.files}" />
        </concat>
        
        <apply executable="java" verbose="true" dest="bin" failonerror="true" parallel="false">
            <fileset dir="dev\${yak.path}js" includes="yakbootstrap*.js, konami.js, run.js" excludes="" />
            <arg line="-jar"/>
            <arg path="${closure.path}"/>
            <arg value="--js"/>
            <srcfile/>
            <arg value="--js_output_file"/>
            <targetfile/>
            <mapper type="glob" from="*.js" to="*.min.js"/>
        </apply>

        <apply executable="java" verbose="true" dest="bin" failonerror="true" parallel="false">
            <fileset dir="bin" includes="main.js"/>
            <arg line="-jar"/>
            <arg path="${closure.path}"/>
            <arg value="--js"/>
            <srcfile/>
            <arg value="--js_output_file"/>
            <targetfile/>
            <mapper type="glob" from="*.js" to="*.min.js"/>
        </apply>
        <copy file="bin\main.min.js" todir="${yak.path}js" overwrite="true" />
        <!--<delete file="bin\main.js" />-->
        
        <mkdir dir="doc" />
        <exec executable="cmd" dir="bin">
            <arg line="/c yuidoc ."/>
        </exec>        
        <copy todir="doc">
            <fileset dir="bin\out" />
        </copy>
        <delete dir="bin\out" />
    </target>
    
    <target name="css">
        <!--<concat destfile="bin\_style.css" fixlastline="true">
            <filelist dir="dev\${yak.path}css" files="style.css" />
        </concat>-->
        
        <apply executable="java" verbose="true" dest="bin" failonerror="true" parallel="false">
            <fileset dir="dev\${yak.path}css" includes="style.css"/>
            <arg line="-jar"/>
            <arg path="${yuicompressor.path}"/>
            <arg value="--type"/>
            <arg value="css"/>
            <srcfile/>
            <arg value="-o"/>
            <targetfile/>
            <mapper type="glob" from="*.css" to="*.css"/>
        </apply>
        <copy file="bin\style.css" todir="${yak.path}css" overwrite="true" />
    </target>
    
    <target name="html">
        <copy file="dev\index.html" todir="." overwrite="true" />
        <replaceregexp flags="gs">
            <regexp pattern='(ui.min.js">\\x3C/script)(.*?)run.js' />
            <substitution expression='\1\&gt;\&apos;)\&lt;/script\&gt;\&#10;\&lt;script type="text/javascript" src="resources/yakbootstrap/js/main.min.js' />
            <fileset dir="." includes="index.html" />
        </replaceregexp>
    </target>
    
    <target name="yakbootstrap" depends="js,css, html">
        <echo message="Build complete."/>
    </target>
</project>

相关推荐