<!--
 * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 * 
 * This software is the property of WSO2 Inc. and its suppliers, if any.
 * Dissemination of any information or reproduction of any material contained
 * herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 * You may not alter or remove any copyright or other notice from copies of this content."
-->

<project name="identity-apps" basedir=".">

    <!-- Create dependency dir -->
    <target name="check-dependencies-dir">
        <available property="dependencies.dir.exists" file="dependencies/" type="dir"/>
    </target>

    <target name="create-dependencies-dir" depends="check-dependencies-dir" unless="dependencies.dir.exists">
        <mkdir dir="dependencies"/>  
    </target>

    <!-- Download dependency -->
    <target name="check-dependency" depends="create-dependencies-dir">
        <available file="dependencies/v${identity.apps.version}.zip" property="dependency.exists"/>
    </target>

    <target name="download-dependency" depends="check-dependency" unless="dependency.exists">
        <get src="https://github.com/wso2/identity-apps/archive/v${identity.apps.version}.zip"
             dest="dependencies/"
             verbose="false"
             usetimestamp="true"/>
    </target>

    <!-- Apply changes -->
    <target name="extract-dependency">
        <unzip src="dependencies/v${identity.apps.version}.zip" dest="target" overwrite="true"/>
        <chmod file="target/identity-apps-${identity.apps.version}" perm="700"/>
        <move todir="target/identity-apps">
            <fileset dir="target/identity-apps-${identity.apps.version}"/>
        </move>
    </target>

    <target name="copy-developer-portal-extensions">
        <echo message="--- copying developer-portal extensions ---"/>
        <copy todir="target/identity-apps/apps/developer-portal/src/extensions/" overwrite="true">
            <fileset dir="app-extensions/developer-portal/src/extensions/" includes="**" />
        </copy>
        <copy todir="target/identity-apps/" file="app-extensions/lerna.json" overwrite="true"/>
        <copy todir="target/identity-apps/apps/developer-portal/src/public/" file="app-extensions/developer-portal/src/public/deployment.config.json" overwrite="true"/>
    </target>

    <target name="go" depends="check-dependency, download-dependency, extract-dependency, copy-developer-portal-extensions" />

</project>
