<project>
    <target name="html">
        <antcall target="html-build"></antcall>
        <antcall target="html-build-docs"></antcall>
        <antcall target="html-build-release"></antcall>
        <antcall target="html-build-themeforest"></antcall>
        <antcall target="html-build-demo"></antcall>
    </target>

    <target name="html-build">
        <echo message="Removing Old HTML..." />
        <!-- remove old artifacts -->
        <delete includeEmptyDirs="true" failonerror="false">
            <fileset dir="artifacts/html" />
        </delete>

        <!-- create artifiacts folder -->
        <mkdir dir="artifacts/html" />

        <echo message="composer install" />
        <exec executable="bash" dir="html">
            <arg value="-c"/>
            <arg value="composer install"/>
        </exec>

        <echo message="Building HTML..." />
        <assemble dir="html"></assemble>
        <copy todir="artifacts/html/build">
            <fileset dir="html/dist" />
        </copy>

        <!-- zip up the html build -->
        <zip basedir="html/dist" destfile="artifacts/html/build.zip" />
    </target>

    <target name="html-build-demo" if="${html.hasdemo}">

        <echo message="Building Demo..." />
        <assemble dir="html" grunt="demo"></assemble>

        <!-- zip up the demo html build -->
        <zip basedir="html/dist" destfile="artifacts/html/demo.zip" />
    </target>

    <target name="html-build-docs">
        <echo message="Copying changelog..." />
        <copy todir="docs/html/src/templates/pages" overwrite="true">
            <fileset file="html/changelog.md" />
        </copy>

        <echo message="number: ${html.version}" file="docs/html/src/data/version.yml"></echo>

        <echo message="Building Docs..." />
        <assemble dir="docs/html"></assemble>
        <copy todir="artifacts/html/docs">
            <fileset dir="docs/html/dist" />
        </copy>

        <!-- zip up the theme docs -->
        <zip basedir="artifacts/html/docs" destfile="artifacts/html/docs.zip" />
    </target>

    <target name="html-build-release">
        <echo message="Building Release..." />
        <!-- remove old release folder -->
        <delete includeEmptyDirs="true" failonerror="false">
            <fileset dir="artifacts/html/release" />
        </delete>

        <mkdir dir="artifacts/html/release" />

        <!-- zip up the html build -->
        <lower string="${project.name}" to="project.namelower" />
        <zip basedir="html/dist" destfile="artifacts/html/release/${project.namelower}.zip" />

        <!-- copy docs -->
        <copy todir="artifacts/html/release/docs">
            <fileset dir="docs/html/dist" />
        </copy>

        <!-- copy bundles -->
        <copy todir="artifacts/html/release">
            <fileset dir="themeforest/html" includes="${html.bundles.html}" />
            <fileset dir="themeforest/shared" includes="${html.bundles.shared}" />
        </copy>
    </target>

    <target name="html-build-themeforest">
        <lower string="${project.name}" to="project.namelower" />

        <echo message="Building Themeforest..." />
        <!-- remove old themeforest folder -->
        <delete includeEmptyDirs="true" failonerror="false">
            <fileset dir="artifacts/html/themeforest" />
        </delete>

        <mkdir dir="artifacts/html/themeforest" />

        <echo message="Creating Theme Preview..." />
        <zip basedir="themeforest/html/submit/preview" destfile="artifacts/html/themeforest/theme-preview.zip" />

        <echo message="Creating Thumbnail..." />
        <copy file="themeforest/html/submit/thumbnail.png" tofile="artifacts/html/themeforest/thumbnail.png" />

        <!-- zip main release up -->
        <zip basedir="artifacts/html/release" destfile="artifacts/html/themeforest/${project.namelower}-${html.version}.zip" />
    </target>

    <target name="html-upload-themeforest">
        <upload-to-tf dir="html"></upload-to-tf>
    </target>
</project>