<?xml version="1.0"?>
<!--
  kissy 构建文件，开启每个组件的构建
  @author lifesinger@gmail.com , yiminghe@gmail.com
-->
<project name="kissy-project-build" xmlns:ac="antlib:net.sf.antcontrib">
    <description>KISSY Project Build File</description>

    <!-- kissy 主目录 -->
    <property name="kissy.dir" location="${ant.file.kissy-project-build}/../../"/>
    <!-- kissy 工具目录 -->
    <property name="kissy-tools.dir" location="${kissy.dir}/../kissy-tools/"/>
    <!-- kissy build 目录 -->
    <property name="kissy.build.dir" location="${kissy.dir}/build/"/>
    <!-- kissy 源码目录 -->
    <property name="kissy.src.dir" location="${kissy.dir}/src/"/>
    <!-- kissy 源码编码 -->
    <property name="charset" value="utf-8"/>

    <property name="git.origin" value="origin"/>
    <property name="git.remote" value="remote"/>
    <property name="git.master" value="1.3.x"/>
    <property name="js-css.files" value="**/*.js,**/*.css"/>
    
    <import file="./version.xml"/>


    <!--
        打包 core kissy
    -->
    <target name="combine-core">
        <subant target="" failonerror="false" inheritall="false">
            <fileset dir="./build-xml/core/" includes="**/build.xml"/>
        </subant>
    </target>

    <!--
      全部构建
    -->
    <target name="build-all">
        <!--
        各个组件构建
        // https://issues.apache.org/bugzilla/show_bug.cgi?id=33061 oom
        -->
        <subant target="" failonerror="false" inheritall="false">
            <fileset dir="${kissy.src.dir}" includes="**/build.xml"/>
        </subant>
        <subant target="combine-core"
                buildpath="."
                inheritall="false" inheritrefs="false"/>
    </target>

    <!--
    push to branches
    -->
    <target name="sync">
        <input addproperty="git.commit.message">
            git commit message :
        </input>
        <ac:if>

            <not>
                <equals arg1="${git.commit.message}" arg2="">
                </equals>
            </not>

            <ac:then>

                <exec executable="cmd"
                      failonerror="true">
                    <arg line="/c git add ."/>
                </exec>
                <exec executable="cmd" failonerror="true">
                    <arg line="/c git commit -am '${git.commit.message}'"/>
                </exec>

            </ac:then>
        </ac:if>

        <exec executable="cmd" failonerror="true">
            <arg line="/c git push ${git.origin} ${git.master}:${git.master}"/>
        </exec>
        
        <exec executable="cmd" failonerror="true">
            <arg line="/c git push ${git.remote} ${git.master}:${git.master}"/>
        </exec>
        
    </target>


    <target name="sync-dev">
        <input addproperty="git.commit.message">
            git commit message :
        </input>
        <ac:if>

            <not>
                <equals arg1="${git.commit.message}" arg2="">
                </equals>
            </not>

            <ac:then>

                <exec executable="cmd"
                      failonerror="true">
                    <arg line="/c git add ."/>
                </exec>
                <exec executable="cmd" failonerror="true">
                    <arg line="/c git commit -am '${git.commit.message}'"/>
                </exec>

            </ac:then>
        </ac:if>

        <exec executable="cmd" failonerror="true">
            <arg line="/c git push ${git.origin} ${git.dev}:${git.dev}"/>
        </exec>

        <exec executable="cmd" failonerror="true">
            <arg line="/c git push ${git.remote} ${git.dev}:${git.dev}"/>
        </exec>

    </target>
    
    <target name="update-version">
        <replaceregexp match="v\d.\d\d"
                       replace="v${version}"
                       flags="g"
                       encoding="${charset}"
                       byline="true">
            <fileset dir="${kissy.build.dir}" includes="${js-css.files}"/>
        </replaceregexp>
        
        <replaceregexp match="version:\s*['&quot;]\d.\d\d['&quot;]"
                       replace="version:'${version}'"
                       flags="g"
                       encoding="${charset}"
                       byline="true">
            <fileset dir="${kissy.build.dir}" includes="${js-css.files}"/>
        </replaceregexp>
        
    </target>

    <target name="clean">
        <delete dir="${kissy.build.dir}"/>
    </target>

</project>
