<project name="x-js-impl">
    <!--
    this target extracts split mode information from the compiler's app
    processor to determine various pieces of information
    -->
    <target name="-detect-app-build-properties" 
            depends="-init-app-js-files">
        <x-load-app-builder-properties
            refid="${compiler.ref.id}"
            splitModePropName="enable.split.mode"
            pageModePropName="app.page.mode"
            hasJsSdkPropName="app.has.js.sdk"
            hasCssSdkPropName="app.has.css.sdk"
            hasUsesPackagesPropName="app.has.uses" />
    </target>

    <!--    
    this is the standard js compile target that builds the output js file(s)
    -->
    <target name="-compile-js" depends="-detect-app-build-properties">
        <if>
            <x-is-true value="${enable.split.mode}"/>
            <then>
                <local name="build.js.framework.fwset" />
                <local name="build.js.framework.rtl" />
                <if>
                    <or>
                        <x-is-true value="${app.output.framework.all}" />
                        <isset property="app.has.uses" />
                    </or>
                    <then>
                        <property name="build.include.all.scss" value="true" />
                        <property name="build.js.framework.fwset"> </property>
                        <if>
                            <x-is-false value="${app.output.framework.rtl}" />
                            <then>
                                <property name="build.js.framework.rtl">
                                    <![CDATA[
                                        exclude
                                            -namespace=Ext.rtl
                                        and
                                    ]]>
                                </property>
                            </then>
                            <else>
                                <property name="build.js.framework.rtl"> </property>
                            </else>
                        </if>
                    </then>
                    <else>
                        <property name="build.js.framework.fwset">
                            <![CDATA[
                                intersect
                                    -set=page,allframework
                                and
                            ]]>
                        </property>
                        <property name="build.js.framework.rtl"> </property>
                    </else>
                </if>

                <property name="app.output.framework.include"
                          value="package-sencha-core,framework,toolkit,package-core"/>

                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                        # build a separate sdk-only js file
                        restore
                            page
                        and
                        ${build.optimize}
                        and
                        exclude
                            -all
                        and
                        include
                            -tag=${app.output.framework.include}
                        and
                        save
                            allframework
                        and
                        ${build.js.framework.fwset}
                        save
                            frameworkdeps
                        and
                        ${build.js.framework.rtl}
                        include
                            -tag=Ext.cmd.derive
                        and
                        concat
                            -remove-text-references=${build.remove.references}
                            -optimize-string-references=${build.optimize.string.references}
                            -remove-requirement-nodes=${build.remove.requirement.nodes}
                            ${build.compression}
                            -out=${build.framework.file}
                            ${build.concat.options}
                        
                        # now build the all-classes file, without
                        # the framework code included
                        and
                        restore
                            page
                        and
                        exclude
                            -set=frameworkdeps
                        and
                        exclude
                            -tag=Ext.cmd.derive,derive
                        and
                        concat
                            -remove-text-references=${build.remove.references}
                            -optimize-string-references=${build.optimize.string.references}
                            -remove-requirement-nodes=${build.remove.requirement.nodes}
                            ${build.compression}
                            -out=${build.classes.file}
                            ${build.concat.options}
                    ]]>
                </x-compile>
            </then>
            <else>
                <local name="framework.include.filter"/>
                <if>
                    <isset property="app.has.uses"/>
                    <then>
                        <property name="app.output.framework.include"
                                  value="package-sencha-core,framework,toolkit,package-core"/>
                        
                        <property name="framework.include.filter">
                            include
                                -tag=${app.output.framework.include}
                            and
                        </property>
                    </then>
                    <else>
                        <property name="framework.include.filter">
                            #no-op
                        </property>
                    </else>
                </if>
                <x-compile refid="${compiler.ref.id}">
                    <![CDATA[
                        # build an all-classes.js file that contains
                        # all code needed by the app
                        restore
                            page
                        and
                        ${framework.include.filter}
                        ${build.optimize}
                        and
                        concat
                            -remove-text-references=${build.remove.references}
                            -optimize-string-references=${build.optimize.string.references}
                            -remove-requirement-nodes=${build.remove.requirement.nodes}
                            ${build.compression}
                            -out=${build.classes.file}
                            ${build.concat.options}
                    ]]>
                </x-compile>
            </else>
        </if>
    </target>
    
    <!--    
    Build javascript
    -->
    <target name="-before-js"/>
    <target name="-js" depends="-compile-js"/>
    <target name="-after-js"/>
</project>