<project name="editor.build" default="build" basedir=".">
    <description>Editor Build File</description>

    <property name="component.name" value="editor"/>

    <import file="../../tools/build-xml/common.xml"/>

    <property name="smartsprites.basedir" location="${kissy-tools.dir}/smartsprites/"/>
    <property name="editor.theme.tmp.dir" location="${component.src.dir.tmp}/theme/"/>
    <property name="editor.theme.dir" location="${component.src.dir}/editor/theme/"/>


    <taskdef resource="smartsprites.xml">
        <classpath>
            <fileset dir="${smartsprites.basedir}/lib">
                <include name="*.jar"/>
            </fileset>
        </classpath>
    </taskdef>

    <target name="editor-prepare">
        <copy todir="${component.src.dir.tmp}"
              encoding="${charset}"
              outputencoding="${charset}">
            <fileset dir="${component.src.dir}/editor/"
                     excludes="core/*,theme/cool/*.css"
            />
        </copy>
    </target>

    <target name="editor-js">
        <concat destfile="${component.src.dir.tmp}/editor-pkg.js" encoding="${charset}" outputencoding="${charset}">
            <fileset dir="${component.src.dir}/editor/core"
                     includes="**/*.js"/>
            <filterchain>
                <deletecharacters chars="${bom}"/>
            </filterchain>
        </concat>
    </target>


    <target name="editor-css">
        <concat destfile="${editor.theme.tmp.dir}/cool/editor-pkg.css"
                encoding="${charset}" outputencoding="${charset}">
            <path location="${editor.theme.dir}/editor-common.css"/>
            <fileset dir="${editor.theme.dir}/cool/" includes="**/*.css"/>
            <filterchain>
                <deletecharacters chars="${bom}"/>
            </filterchain>
        </concat>

        <smartsprites cssfilesuffix="-sprite"
                      spritepngie6="true"
                      loglevel="info">
            <fileset file="${editor.theme.tmp.dir}/cool/editor-pkg.css"/>
        </smartsprites>

        <move tofile="${editor.theme.tmp.dir}/cool/editor.css">
            <path location="${editor.theme.tmp.dir}/cool/editor-pkg-sprite.css"/>
        </move>
    </target>

    <target name="editor-full">
        <concat destfile="${component.src.dir.tmp}/full.js">
            <path location="${component.src.dir.tmp}/editor-pkg.js"/>
            <fileset dir="${component.src.dir.tmp}/plugin/"
                     excludes="**/dialog.js,**/dynamic/**/*.js"
                     includes="**/*.js"/>
            <filterchain>
                <deletecharacters chars="${bom}"/>
            </filterchain>
            <path location="${component.src.dir}/editor/full.js"/>
        </concat>
    </target>

    <target name="editor" depends="editor-prepare,editor-js,editor-css,editor-full">

    </target>


    <target name="extract-dependency">
        <java classname="com.taobao.f2e.ExtractDependency" fork="true">

            <arg value="-baseUrls"/>
            <arg value="${component.src.dir}/editor/plugin/"/>

            <arg value="-encodings"/>
            <arg value="${charset}"/>

            <arg value="-outputEncoding"/>
            <arg value="utf-8"/>

            <arg value="-output"/>
            <arg value="${component.src.dir}/editor/core/modules.js"/>

            <classpath>
                <pathelement path="${kissy-tools.module-compiler}"/>
                <pathelement path="${java.class.path}"/>
            </classpath>
        </java>

        <mkdir dir="${component.meta.dir}"/>

        <java classname="com.taobao.f2e.ExtractDependency" fork="true">

            <arg value="-baseUrls"/>
            <arg value="${component.src.dir}/editor/core/"/>

            <arg value="-encodings"/>
            <arg value="${charset}"/>

            <arg value="-nameMap"/>
            <arg value="(editor)(?:/.*)?||$1"/>

            <arg value="-outputEncoding"/>
            <arg value="utf-8"/>

            <arg value="-compact"/>
            <arg value="true"/>

            <arg value="-output"/>
            <arg value="${component.meta.dir}/modules.js"/>

            <classpath>
                <pathelement path="${kissy-tools.module-compiler}"/>
                <pathelement path="${java.class.path}"/>
            </classpath>
        </java>
    </target>

    <target name="build" depends="extract-dependency,editor,common-build.process">
    </target>
</project>
