<project name="refresh-impl">
    <!--
    This macrodef regenerates the bootstrap.js class system metadata, which includes
    relative file paths, class names, alternate class names, and class alias data
    -->
    <macrodef name="x-run-bootstrap">
        <attribute name="file"/>
        <attribute name="basedir"/>
        <attribute name="appendMicroloader" default="false"/>
        <sequential>
            
            <local name="tag.filter"/>
            <local name="ux.include"/>
            <local name="load.script.tpl"/>
        
            <condition property="tag.filter" value="package-sencha-core,core">
                <x-is-true value="${enable.sencha-core.filter}"/>
            </condition>
            <property name="tag.filter" value="core"/>
            
            <if>
                <equals arg1="${framework.name}" arg2="ext"/>
                <then>
                    <property name="ux.include">
                    include
                        -namespace=Ext.ux
                    and
                    </property>
                    <property name="load.script.tpl" value="Ext.Loader.loadScript(&quot;{0}&quot;);"/>
                </then>
                <else>
                    <property name="ux.include" value=""/>
                    <property name="load.script.tpl" value="Ext.Loader.loadScriptFile(&quot;{0}&quot;, Ext.emptyFn);"/>
                </else>
            </if>
            
<echo file="@{file}">
/**
 * This file is generated by Sencha Cmd and should NOT be edited.  It is 
 * provided to support globbing requires, custom xtypes, and other 
 * metadata-driven class system features 
 */
</echo>
            <x-compile refid="${compiler.ref.id}">
                <![CDATA[
                    union
                        -not
                        -tag=${tag.filter}
                    and
                    metadata
                        +append
                        -base-path=@{basedir}
                        +loader-paths
                        -jsonp=Ext.Loader.addClassPathMappings
                        -out=@{file}
                    and
                    exclude
                        -tag=${tag.filter}
                    and
                    ${ux.include}
                    metadata
                        +append
                        -base-path=@{basedir}
                        +alternates
                        -out=@{file}
                    and
                    metadata
                        +append
                        -base-path=@{basedir}
                        +alias
                        -out=@{file}
                    and
                    meta
                        +append
                        +packages
                        -out=@{file}
                    and
                    union
                        -tag=overrides
                    and
                    metadata
                        -base-path=@{basedir}
                        +append
                        +filenames
                        -tpl=${load.script.tpl};
                        -out=@{file}
                ]]>
            </x-compile>
        </sequential>
    </macrodef>
   
    <!--
    Refreshes the application's bootstrap javascript and microloader manifest
    '-detect-app-build-properties' is defined in js-impl.xml
    -->
    <target name="-refresh-app" depends="-detect-app-build-properties">
        
        <!--regenerate class system metadata-->
        <x-run-bootstrap file="${app.bootstrap.js}"
                         basedir="${app.bootstrap.base.path}"/>
        
        <!--regenerate json manifest bootstrap data-->
        <if>
            <equals arg1="${app.page.mode}" arg2="xcompile"/>
            <then>
                <!--
                append the microloader and manifest to the end
                of bootstrap.js
                -->
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                    microload
                        -operation=microloader
                        -microloaderPath=${app.microloader.bootstrap}
                        -append
                        -out=${app.bootstrap.js}
                    ]]>
                </x-compile>
            </then>
        </if>

        <!--
        create / overwrite bootstrap.json, which will be used
        by the default development.js microloader
        -->

<echo file="${build.json.bootstrap.path}">
/**
 * This file is generated by Sencha Cmd and should NOT be edited. It is a 
 * combination of content from app.json, and all required package's package.json
 * files.  Customizations should be placed in app.json.
 */
</echo>
        <x-compile refid="${compiler.ref.id}">
            <![CDATA[
            microload
                -operation=json
                -bootstrap
                -append
                -tpl={0}
                -out=${build.json.bootstrap.path}
            ]]>
        </x-compile>
    </target>
    
    <!--
    Refresh app
    -->
    <target name="-before-refresh"/>
    <target name="-refresh" depends="-refresh-app"/>
    <target name="-after-refresh"/>
</project>