<?xml version="1.0" encoding="UTF-8"?>
<project name="fabrik_js" default="build_js">
	<!--Build -->
	<target name="build_js" description="lints and builds js project files for production use"
		depends="load.properties">
		<antcall target="js.lint"></antcall>
	</target>

	<target name="load.properties" description="Set properties for this build">
		<echo>load properties</echo>
		<!--YUI Compressor location -->
		<property name="yui.dir"
			value="${basedir}/fabrik_build/yuicompressor/build/yuicompressor-2.4.6.jar" />
		<!--Source JS dir -->
		<property name="src.js.dir" value="${basedir}/media/com_fabrik/js" />
		<!--Source CSS dir -->
		<property name="src.css.dir" value="${basedir}/media/com_fabrik/css" />
		<!--Source Lint/Hint dir -->
		<property name="jslint.js" value="${basedir}/fabrik_build/lint/jshint.js" />
		<!--Rhino dir -->
		<property name="js.jar" value="${basedir}/fabrik_build/lint/rhino/js.jar" />
		<!-- Rhino lint -->
		<property name="jshint-rhino.js" value="${basedir}/fabrik_build/lint/jshint-rhino.js" />
		<!--Output dir -->
		<property name="build.dir" value="${basedir}/media/com_fabrik/" />
		<!--Build version information -->
		<property name="build.major" value="1" />
		<property name="build.minor" value="1" />
		<property name="jshint.flags"
			value="browser=true,mootools=true,white=true,loopfunc=true,expr=true,evil=true,boss=true,maxerr=25,undef=false,curly=true,debug=false,eqeqeq=true,immed=true,newcap=true" />
		<property name="jshint.predef"
			value="console,confirm" />
		<property name="jshint.predef.test"
			value="${jshint.predef},icon" />

	</target>

	<!--JS Lint -->
	<target name="js.lint">
		<input message="JS Dir?" addproperty="dir" defaultvalue="media/com_fabrik/js/" />
		<input message="JS file?" addproperty="jsfile" defaultvalue="media/com_fabrik/js/list.js" />
	
		<antcall target="js.lint.do">
			<param name="file" value="${jsfile}" />
		</antcall>
		<antcall target="js.minify.do">
			<param name="file" value="${jsfile}" />
			<param name="dir" value="${dir}" />
		</antcall>
		
	</target>
	
	<target name="js.lint.do">
		<echo>file = ${file}</echo>
		<apply dir="${basedir}/fabrik_build/lint" failonerror="true" executable="java" errorproperty="linterror" resultproperty="lintresult">
			<fileset file="${file}">
			</fileset>
			<arg line="-jar ${js.jar} ${jshint-rhino.js}" />
			<srcfile />
			<arg value="${jshint.flags}" />
			<arg value="${jshint.predef}" />
		</apply>
		<echo>lint error: ${linterror}</echo>
		<echo>lint result: ${lintresult}</echo>
		<!--  0 is no errors - > 0 is an erorr count -->
		<echo>${file} JSHint Passed</echo>
	</target>
	
		<!--Minify JS files -->
	<target name="js.minify.do" description="Minifies JavaScript files">
		<echo>file = ${file}</echo>
		<apply executable="java" parallel="false" dest="${dir}" failonerror="true" >
			<fileset file="${file}">
			</fileset>
			<arg line="-jar" />
			<arg path="${yui.dir}" />
			<srcfile />
			<arg line="-o" />
			
			<mapper type="glob" from="*.js" to="*-min.js" />
			<targetfile />
		</apply>
		<echo>Finished</echo>
	</target>
</project>