<?xml version="1.0"?>
<project name="Contao Open Source CMS" default="build" basedir=".">
  <exec executable="system/bin/version" outputProperty="version" />

  <target name="build" depends="clone, update, languages, purge, pack, cleanup">
    <echo message="Contao ${version} build complete" />
  </target>

  <target name="clone">
    <echo message="Cloning into contao-${version}" />
    <exec executable="git">
      <arg value="clone" />
      <arg value="." />
      <arg value="contao-${version}" />
    </exec>
    <exec executable="git" dir="contao-${version}">
      <arg value="checkout" />
      <arg value="--quiet" />
      <arg value="${version}" />
    </exec>
    <exec executable="git" dir="contao-${version}">
      <arg value="reset" />
      <arg value="--hard" />
    </exec>
  </target>

  <target name="update">
    <exec executable="composer" dir="contao-${version}" passthru="true">
      <arg value="install" />
      <arg value="--prefer-dist" />
      <arg value="--no-dev" />
      <arg value="--no-scripts" />
    </exec>
  </target>

  <target name="languages">
    <exec executable="txget" dir="contao-${version}" passthru="true" />
  </target>

  <target name="purge">
    <delete dir="contao-${version}/.tx" />
    <delete dir="contao-${version}/.git" />
    <delete dir="contao-${version}/vendor/simplepie/simplepie/compatibility_test" />
    <delete dir="contao-${version}/vendor/simplepie/simplepie/demo" />
    <delete dir="contao-${version}/vendor/tecnickcom/tcpdf/examples" />
    <delete includeemptydirs="true" verbose="true">
      <fileset dir="contao-${version}/vendor" includes="*/*/demo/**,*/*/doc/**,*/*/docs/**,*/*/notes/**,*/*/site/**,*/*/test/**,*/*/tests/**" />
    </delete>
    <delete includeemptydirs="true" verbose="true">
      <fileset dir="contao-${version}/vendor/tecnickcom/tcpdf/fonts" excludes="courier.php,freeserif*.*,helvetica*.php" />
    </delete>
  </target>

  <target name="pack">
    <exec executable="zip">
      <arg value="-r" />
      <arg value="contao-${version}.zip" />
      <arg value="contao-${version}/" />
    </exec>
    <exec executable="tar">
      <arg value="-czf" />
      <arg value="contao-${version}.tar.gz" />
      <arg value="contao-${version}/" />
    </exec>
  </target>

  <target name="cleanup">
    <delete dir="contao-${version}" />
  </target>
</project>
