Web前端开发的持续构建环境的搭建,主要完成以下几个目标:
<taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpath="./build/jslint4java-2.0.2.jar" /> <target name="jslint" depends="clean"> <mkdir dir="${stat.result.folder}/jslintOutput"></mkdir> <jslint failureProperty="false" haltOnFailure="false"> <formatter type="checkstyle" destfile="${stat.result.folder}/jslintOutput/jslintresult.xml"/> <fileset dir="scripts"> <include name="**/*.js"/> <exclude name="require.js"/> </fileset> </jslint> </target>
server: http://localhost:9876 load: - ../scripts/*.js - ../scripts-test/*.js
<target name="jsut" depends="clean"> <mkdir dir="${stat.result.folder}/jsUTOutput"></mkdir> <java jar="build/JsTestDriver-1.3.4.b.jar" fork="true" failonerror="true"> <arg value="--port"/> <arg value="9876"/> <arg value="--config"/> <arg value="build/jsTestDriver.conf"/> <arg value="--browser"/> <arg value="C:\Users\juns6831.CHN\AppData\Local\Google\Chrome\Application\chrome.exe"/> <arg value="--tests"/> <arg value="all"/> <arg value="--testOutput"/> <arg value="${stat.result.folder}/jsUTOutput"/> </java> </target>
node r.js -o name=main out=../%1/scripts/main.js baseUrl=../scripts node r.js -o cssIn=../css/main.css out=../%1/css/main.css optimizeCss="standard.keepLines"
<target name="minify" depends="clean"> <exec executable="cmd" osfamily="windows" dir="build" failonerror="true"> <arg value="/c"/> <arg value="minify.bat"/> <arg value="${target.folder}"/> <arg value="-p"/> </exec> </target>
<!DOCTYPE html> <html> <head> <title>My Sample Project</title> <script data-main="scripts/main" src="scripts/require.js"></script> </head> <body> <h1>My Sample Project</h1> </body> </html>
require(["helper/util"], function(util) { //This function is called when scripts/helper/util.js is loaded. //If util.js calls define(), then this function is not fired until //util's dependencies have loaded, and the util argument will hold //the module value for "helper/util". console.log("util js loaded."); console.log(util.a + ',' + util.b); });
GreeterTest = TestCase("GreeterTest"); GreeterTest.prototype.testGreet = function() { var greeter = new myapp.Greeter(); assertEquals("Hello World!", greeter.greet("World")); jstestdriver.console.log("JsTestDriver", greeter.greet("World")); console.log(greeter.greet("Browser", "World")); }; GreeterTest.prototype.testGreet3 = function() { var greeter = new myapp.Greeter(); assertEquals("Hello World!", greeter.greet("World3")); jstestdriver.console.log("JsTestDriver", greeter.greet("World3")); console.log(greeter.greet("Browser", "World3")); }; GreeterTest2 = TestCase("GreeterTest2"); GreeterTest2.prototype.testGreet2 = function() { var greeter = new myapp.Greeter(); assertEquals("Hello World2!", greeter.greet("World2")); jstestdriver.console.log("JsTestDriver", greeter.greet("World2")); console.log(greeter.greet("Browser", "World2")); };
@import url("common.css"); body{ color:red }
body{ font-size:14px; }
<project name="js build" default="install" basedir="."> <property name="target.folder" value="target" /> <property name="stat.result.folder" value="stat-result" /> <property name="tomcat.webapp" value="D:\apache-tomcat-6.0.32\webapps"></property> <taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpath="./build/jslint4java-2.0.2.jar" /> <target name="jslint" depends="clean"> <mkdir dir="${stat.result.folder}/jslintOutput"></mkdir> <jslint failureProperty="false" haltOnFailure="false"> <formatter type="checkstyle" destfile="${stat.result.folder}/jslintOutput/jslintresult.xml"/> <fileset dir="scripts"> <include name="**/*.js"/> <exclude name="require.js"/> </fileset> </jslint> </target> <target name="jsut" depends="clean"> <mkdir dir="${stat.result.folder}/jsUTOutput"></mkdir> <java jar="build/JsTestDriver-1.3.4.b.jar" fork="true" failonerror="true"> <arg value="--port"/> <arg value="9876"/> <arg value="--config"/> <arg value="build/jsTestDriver.conf"/> <arg value="--browser"/> <arg value="C:\Users\juns6831.CHN\AppData\Local\Google\Chrome\Application\chrome.exe"/> <arg value="--tests"/> <arg value="all"/> <arg value="--testOutput"/> <arg value="${stat.result.folder}/jsUTOutput"/> </java> </target> <target name="minify" depends="clean"> <exec executable="cmd" osfamily="windows" dir="build" failonerror="true"> <arg value="/c"/> <arg value="minify.bat"/> <arg value="${target.folder}"/> <arg value="-p"/> </exec> </target> <target name="build" depends="jslint,jsut,minify"> <copy todir="${target.folder}"> <fileset dir="${basedir}"> <include name="*.html"></include> </fileset> </copy> <copy file="scripts/require.js" todir="${target.folder}/scripts"></copy> </target> <target name="install" depends="build"> <mkdir dir="${tomcat.webapp}/jsci"></mkdir> <copy todir="${tomcat.webapp}/jsci"> <fileset dir="${target.folder}"></fileset> </copy> </target> <target name="clean"> <delete dir="${target.folder}"></delete> <delete dir="${tomcat.webapp}/jsci"></delete> <delete dir="${stat.result.folder}"></delete> </target> </project>