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

    <target name="angularjs-dev">
        <antcall target="angularjs-build"></antcall>
        <antcall target="angularjs-build-demo"></antcall>
    </target>

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

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

        <echo message="Copy app source..." />
        <copy todir="artifacts/build">
            <fileset dir="app" excludes="${angular.src.exclude}"></fileset>
        </copy>
    </target>

    <target name="angularjs-build-demo">
        <echo message="Building Demo..." />

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

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

        <echo message="grunt build" />
        <exec executable="bash" dir="app">
            <arg value="-c"/>
            <arg value="gulp build"/>
        </exec>

        <echo message="Copy demo source..." />
        <copy todir="artifacts/demo">
            <fileset dir="app/dist"></fileset>
        </copy>

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

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

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

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

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

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

        <mkdir dir="artifacts/release" />

        <!-- copy the app -->
        <copy todir="artifacts/release/app">
            <fileset dir="artifacts/build" />
        </copy>

        <!-- copy the built demo -->
        <copy todir="artifacts/release/" overwrite="true">
            <fileset file="artifacts/demo.zip" />
        </copy>

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

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

    <target name="angularjs-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/themeforest" />
        </delete>

        <mkdir dir="artifacts/themeforest" />

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

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

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