Skip to content
Permalink
Browse files

Deploy release build.xml

  • Loading branch information
eduardolundgren committed Jun 7, 2008
1 parent 9383692 commit e2d2ed1eb0334b125d59f0f549ea312501ef2720
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="iso-8859-1"?>

<!--
jQuery UI Release!
Call task called 'deploy-release' to build a full release.
The release built will be stored on 'dist' dir.
@author Eduardo Lundgren (eduardo.lundgren@gmail.com)
-->

<project name="jquery-ui" default="deploy-release" basedir=".">

<target name="deploy-release" depends="load.properties, concatenate, minify, pack, copy" description="Release builder">
</target>

<target name="load.properties">
<property file="ant.properties" />

<property name="dist.dir" value="dist" />
<property name="build.dir" value="build" />
<property name="ui.dir" value="../" />
<property name="src.dir" value="${ui.dir}/ui/" />

<property name="min.folder" value="${dist.dir}/ui/minified" />
<property name="packed.folder" value="${dist.dir}/ui/packed" />

<property name="concatenated" value="jquery-ui-all" />

<property name="core.files" value="ui.core.js, ui.draggable.js, ui.droppable.js, ui.resizable.js, ui.selectable.js, ui.sortable.js, effects.core.js" />

<property description="YUI Compressor" name="yui-jar" value="${build.dir}/yuicompressor.jar" />
<property description="Rhino JS Engine" name="jar" value="${build.dir}/js.jar" />
</target>

<target name="concatenate" depends="load.properties">
<echo message="Building concatenated" />
<mkdir dir="${dist.dir}/ui/" />
<delete file="${dist.dir}/ui/${concatenated}.js" />

<concat destfile="${dist.dir}/ui/${concatenated}.js">
<filelist dir="${src.dir}/" files="${core.files}" />
<fileset dir="${src.dir}/" includes="ui.*.js, effects.*.js" excludes="${core.files}" />
</concat>
<echo message="Concatenated built." />
</target>

<target name="minify" depends="load.properties, concatenate" description="Remove all comments and whitespace, no compression, great in combination with GZip">
<echo message="Building minified" />
<delete dir="${min.folder}/" />
<mkdir dir="${min.folder}" />

<apply executable="java" parallel="false">
<filelist dir="${dist.dir}/ui/" files="${concatenated}.js" />
<fileset dir="${src.dir}/" includes="ui.*.js, effects.*.js" />
<arg line="-jar" />
<arg path="${yui-jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${min.folder}/*.min.js" />
<targetfile />
</apply>
<echo message="Minified built." />
</target>


<target name="pack" depends="load.properties, concatenate, minify" description="Remove all comments and whitespace and compress">
<!--
http://dean.edwards.name/download/#packer
http://homepages.nildram.co.uk/~9jack9/download/packer.wsh.zip
-->
<echo message="Building packed" />
<delete dir="${packed.folder}/" />
<mkdir dir="${packed.folder}" />

<apply executable="cmd" parallel="false">
<filelist dir="${min.folder}" files="${concatenated}.min.js" />
<fileset dir="${min.folder}" includes="ui.*.min.js, effects.*.min.js" />
<arg line="/c CScript /nologo ${build.dir}/js/pack.wsf" />
<srcfile />
<arg line=">>" />
<mapper type="glob" from="*.min.js" to="${packed.folder}/*.packed.js" />
<targetfile />
</apply>
<echo message="Packed built." />
</target>


<!--
TODO - Using Rhino Javascript Engine
<target name="pack" depends="load.properties, concatenate" description="Remove all comments and whitespace and compress">
<echo message="Building packed" />
<delete dir="${packed.folder}/" />
<mkdir dir="${packed.folder}" />
<apply executable="java" parallel="false">
<filelist dir="${min.folder}" files="${concatenated}.min.js" />
<fileset dir="${min.folder}" includes="ui.*.min.js, effects.*.min.js" />
<arg line="-jar" />
<arg path="${jar}" />
<arg value="${build.dir}/build/pack.js" />
<srcfile />
<mapper type="glob" from="*.min.js" to="${packed.folder}/*.packed.js" />
<targetfile />
</apply>
<echo message="Packed built." />
</target>
-->

<target description="Copy needed folders" name="copy" depends="load.properties">
<echo message="Copying files" />
<mkdir dir="${dist.dir}" />

<copy overwrite="true" todir="${dist.dir}/ui/">
<fileset dir="${src.dir}/" includes="ui.*.js, effects.*.js" />
</copy>

<copy overwrite="true" todir="${dist.dir}/ui/i18n/" >
<fileset dir="${src.dir}/i18n/" />
</copy>

<copy overwrite="true" todir="${dist.dir}/">
<fileset dir="${ui.dir}/" includes="*.txt" />
</copy>

<copy overwrite="true" todir="${dist.dir}/demos/" >
<fileset dir="${ui.dir}/demos/" />
</copy>

<copy overwrite="true" todir="${dist.dir}/tests/" >
<fileset dir="${ui.dir}/tests/" />
</copy>

<copy overwrite="true" todir="${dist.dir}/themes/" >
<fileset dir="${ui.dir}/themes/" />
</copy>
<echo message="Files copied." />
</target>

<target depends="load.properties" name="clean">
<delete dir="${dist.dir}" />
</target>

</project>
@@ -0,0 +1,11 @@
load("build/js/jsmin.js", "build/js/writeFile.js");

// arguments
var inFile = arguments[0];
var outFile = arguments[1] || inFile.replace(/\.js$/, ".min.js");

var script = readFile(inFile);
var header = script.match(/\/\*(.|\n)*?\*\//)[0];
var minifiedScript = jsmin('', script, 3);

writeFile( outFile, header + minifiedScript );
@@ -0,0 +1,19 @@
load("build/js/writeFile.js");
load("build/js/base2.js");
load("build/js/Packer.js");
load("build/js/Words.js");

// arguments
var inFile = arguments[0];
var outFile = arguments[1] || inFile.replace(/\.js$/, ".pack.js");

// options
var base62 = true;
var shrink = true;

var script = readFile(inFile);
var header = script.match(/\/\*(.|\n)*?\*\//)[0];
var packer = new Packer;
var packedScript = packer.pack(script, base62, shrink);

writeFile(outFile, header + "\n" + packedScript);
BIN +794 KB release/build/js.jar
Binary file not shown.
@@ -0,0 +1,209 @@
/*
Packer version 3.0 (beta 8) - copyright 2004-2007, Dean Edwards
http://www.opensource.org/licenses/mit-license
*/

eval(base2.namespace);

var IGNORE = RegGrp.IGNORE;
var REMOVE = "";
var SPACE = " ";
var WORDS = /\w+/g;

var Packer = Base.extend({
minify: function(script) {
script = script.replace(Packer.CONTINUE, "");
script = Packer.data.exec(script);
script = Packer.whitespace.exec(script);
script = Packer.clean.exec(script);
return script;
},

pack: function(script, base62, shrink) {
script = this.minify(script + "\n");
if (shrink) script = this._shrinkVariables(script);
if (base62) script = this._base62Encode(script);
return script;
},

_base62Encode: function(script) {
var words = new Words(script);
var encode = function(word) {
return words.fetch(word).encoded;
};

/* build the packed script */

var p = this._escape(script.replace(WORDS, encode));
var a = Math.min(Math.max(words.count(), 2), 62);
var c = words.count();
var k = words;
var e = Packer["ENCODE" + (a > 10 ? a > 36 ? 62 : 36 : 10)];
var r = a > 10 ? "e(c)" : "c";

// the whole thing
return format(Packer.UNPACK, p,a,c,k,e,r);
},

_escape: function(script) {
// single quotes wrap the final string so escape them
// also escape new lines required by conditional comments
return script.replace(/([\\'])/g, "\\$1").replace(/[\r\n]+/g, "\\n");
},

_shrinkVariables: function(script) {
// Windows Scripting Host cannot do regexp.test() on global regexps.
var global = function(regexp) {
// This function creates a global version of the passed regexp.
return new RegExp(regexp.source, "g");
};

var data = []; // encoded strings and regular expressions
var REGEXP = /^[^'"]\//;
var store = function(string) {
var replacement = "#" + data.length;
if (REGEXP.test(string)) {
replacement = string.charAt(0) + replacement;
string = string.slice(1);
}
data.push(string);
return replacement;
};

// Base52 encoding (a-Z)
var encode52 = function(c) {
return (c < 52 ? '' : arguments.callee(parseInt(c / 52))) +
((c = c % 52) > 25 ? String.fromCharCode(c + 39) : String.fromCharCode(c + 97));
};

// identify blocks, particularly identify function blocks (which define scope)
var BLOCK = /(function\s*[\w$]*\s*\(\s*([^\)]*)\s*\)\s*)?(\{([^{}]*)\})/;
var VAR_ = /var\s+/g;
var VAR_NAME = /var\s+[\w$]+/g;
var COMMA = /\s*,\s*/;
var blocks = []; // store program blocks (anything between braces {})
// encoder for program blocks
var encode = function(block, func, args) {
if (func) { // the block is a function block

// decode the function block (THIS IS THE IMPORTANT BIT)
// We are retrieving all sub-blocks and will re-parse them in light
// of newly shrunk variables
block = decode(block);

// create the list of variable and argument names
var vars = match(block, VAR_NAME).join(",").replace(VAR_, "");
var ids = Array2.combine(args.split(COMMA).concat(vars.split(COMMA)));

// process each identifier
var count = 0, shortId;
forEach (ids, function(id) {
id = trim(id);
if (id && id.length > 1) { // > 1 char
id = rescape(id);
// find the next free short name (check everything in the current scope)
do shortId = encode52(count++);
while (new RegExp("[^\\w$.]" + shortId + "[^\\w$:]").test(block));
// replace the long name with the short name
var reg = new RegExp("([^\\w$.])" + id + "([^\\w$:])");
while (reg.test(block)) block = block.replace(global(reg), "$1" + shortId + "$2");
var reg = new RegExp("([^{,])" + id + ":", "g");
block = block.replace(reg, "$1" + shortId + ":");
}
});
}
var replacement = "~" + blocks.length + "~";
blocks.push(block);
return replacement;
};

// decoder for program blocks
var ENCODED = /~(\d+)~/;
var decode = function(script) {
while (ENCODED.test(script)) {
script = script.replace(global(ENCODED), function(match, index) {
return blocks[index];
});
}
return script;
};

// encode strings and regular expressions
script = Packer.data.exec(script, store);

// remove closures (this is for base2 namespaces only)
script = script.replace(/new function\(_\)\s*\{/g, "{;#;");

// encode blocks, as we encode we replace variable and argument names
while (BLOCK.test(script)) {
script = script.replace(global(BLOCK), encode);
}

// put the blocks back
script = decode(script);

// put back the closure (for base2 namespaces only)
script = script.replace(/\{;#;/g, "new function(_){");

// put strings and regular expressions back
script = script.replace(/#(\d+)/g, function(match, index) {
return data[index];
});

return script;
}
}, {
CONTINUE: /\\\r?\n/g,

ENCODE10: "String",
ENCODE36: "function(c){return c.toString(a)}",
ENCODE62: "function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))}",

UNPACK: "eval(function(p,a,c,k,e,r){e=%5;if(!''.replace(/^/,String)){while(c--)r[%6]=k[c]" +
"||%6;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p." +
"replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('%1',%2,%3,'%4'.split('|'),0,{}))",

init: function() {
this.data = reduce(this.data, function(data, replacement, expression) {
data.store(this.javascript.exec(expression), replacement);
return data;
}, new RegGrp, this);
this.clean = this.data.union(this.clean);
this.whitespace = this.data.union(this.whitespace);
},

clean: {
"\\(\\s*;\\s*;\\s*\\)": "(;;)", // for (;;) loops
"throw[^};]+[};]": IGNORE, // a safari 1.3 bug
";+\\s*([};])": "$1"
},

data: {
// strings
"STRING1": IGNORE,
'STRING2': IGNORE,
"CONDITIONAL": IGNORE, // conditional comments
"(COMMENT1)\\n\\s*(REGEXP)?": "\n$3",
"(COMMENT2)\\s*(REGEXP)?": " $3",
"([\\[(\\^=,{}:;&|!*?])\\s*(REGEXP)": "$1$2"
},

javascript: new RegGrp({
COMMENT1: /(\/\/|;;;)[^\n]*/.source,
COMMENT2: /\/\*[^*]*\*+([^\/][^*]*\*+)*\//.source,
CONDITIONAL: /\/\*@|@\*\/|\/\/@[^\n]*\n/.source,
REGEXP: /\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*/.source,
STRING1: /'(\\.|[^'\\])*'/.source,
STRING2: /"(\\.|[^"\\])*"/.source
}),

whitespace: {
"(\\d)\\s+(\\.\\s*[a-z\\$_\\[(])": "$1 $2", // http://dean.edwards.name/weblog/2007/04/packer3/#comment84066
"([+-])\\s+([+-])": "$1 $2", // c = a++ +b;
"\\b\\s+\\$\\s+\\b": " $ ", // var $ in
"\\$\\s+\\b": "$ ", // object$ in
"\\b\\s+\\$": " $", // return $object
"\\b\\s+\\b": SPACE,
"\\s+": REMOVE
}
});

0 comments on commit e2d2ed1

Please sign in to comment.
You can’t perform that action at this time.