ESC之ESC.wsf可以实现javascript的代码压缩附使用方法
作者:
可以对javascript的大小进行压缩。使javascript的加载速度变快。
作用:可以对javascript的大小进行压缩。使javascript的加载速度变快。
用法:
在 cmd下面输入的东西;
cscript ESC.wsf -l 3 -ow ../global.js global.js
上面是一个简单的例子:可以自己建一个bat文件放在当前目录下面
cscript ESC.wsf -l 压缩级别 -ow 。。/要压缩到那个目录 需要进行压缩的原js
1.
Level 0 :: No compression //没有处里
Level 1 :: Comment removal //删除掉注释
Level 3 :: Newline removal //删除掉新行
Level 4 :: Variable substitution //变量的替换
2.下图时所用到的参数:
-l 级别
-s
-v
-$
-oa 以追加的形式覆盖
-ow 以覆盖的形式覆盖
所用压缩包在附件 还有帮助文档
使用的例子见压缩包中的图片。
下载地址 http://xiazai.jb51.net/201003/yuanma/ESC.rar
Introduction
ESC is an ECMAScript pre-processor written in JScript, enabling an unlimited number of external scripts to be compressed/crunched into supertight, bandwidth-optimized packages. Featuring several compression-techniques such as comment removal, whitespace stripping, newline stripping and variable substitution ESC can reduce the overall size of your code with up to ~45%. Single, multiple scripts and even directories with scripts can be merged together at the compression level you decide. The processed output can later be appended or written to a file, or piped to another application for further processing via STDOUT. ESC do NOT support crunching of inline scripts. So any attempt passing HTML, ASP, JSP, PHP or other equivalent documents to ESC is done at your own risk. ESC supports four levels of compression, where a higher level equals higher compression. Beware though that levels >2 requires your code to be syntaxically perfect or ESC will punish you by producing a broken and useless output. The compression ratio should hit around 25% using the default compression level on a vanilla looking script, but results as high as ~45% can be achieved depending on the script's design / your style of writing code. ESC's compression engine is intelligent in the meaning that it has language syntax, statement and keyword awareness and it *knows* about native objects and members provided by the most common scripting hosts. This knowledgebase can easily be extended by pluggin in userdefined maps with additional information to further gain control of the crunching procedure. During processing following things are taken into account : String and RegExpression read-ahead
JScript Conditional compilation statements and variables
ECMA-262 Core language definitions (ECMAScript)
Intermediate DOM's (level 0) and DOM level 1
MS JScript specific objects/methods
Netscape/Mozilla/Opera specific objects/methods/properties
MS WSH (Windows Scripting Host) 1+ native objects
Crunching, level by level
Level 0 :: No compression
No compression done. Basically a content transfer/append from input(s) to output. This level is mainly used for tracking down problems occuring to scripts after been shoved through the variable substitution engine.
Level 1 :: Comment removal
ESC removes empty lines (\r?\n)+, single and multi-line and single-line comments (//..., /* ... */) and trailing whitespace. [ \t]+\r?\n
Level 2 :: Whitespace removal
Any occurance of space and tabs (\s\t\r) are removed from the infile(s). This is the default compression-level if none is supplied.
Level 3 :: Newline removal
Newlines (\r?\n) are removed. ESC do not like sloppy written code and will at this level punish you for it by producing a very tight, human unreadable, uninpretable chunk o' chars :) So remember, *ALWAYS* terminate your statements with semi-colons (';'). If you come from a C/C++ bg you have probably been taught this the hard way by an evercroaking compiler. If not for getting your script thru ESC, so start doing it anyway for good ol' programming style.
Level 4 :: Variable substitution
(variable substitution mode, identical to options '-l 3 -$') Additionally to level 3, ESC will run your script(s) through the variable substitution engine. This will certainly break your scripts at the first try, but with a little fiddling around and once you understand how the substitution scheme works, this thing rule since it will save you another extra 5-20% bytewise depending on your coding style. Variable-names less than 3 chars are not affected. Before you try running ESC with variable substitution enabled, I advice you to carefully read the other sections in this manual about the pros and cons, thinking session-dependencies and the known caveats of variable crunching with ESC. Your specific situation in terms of namespaces, shared variables or the design/architecture of your scripts may make it difficult, even impossible to combine with this technique whereas you'll have to stick with level 3.
Examples of usage
X:\cscript ESC.wsf -ow crunched.js original1.js original2.js original3.js Crunch 'original1.js','original2.js' and 'original3.js' at level 2 (default) and save the output as 'crunched.js'. Any previous file named 'crunched.js' will be overwritten.
X:\cscript ESC.wsf -l 1 -oa crunched.js C:\script-directory Grab all scriptfiles (.js) in directory 'C:\script-directory', crunch them at level 1 (comment and empty line removal only) and append the result to 'crunched.js'. If 'crunched.js' doesn't exist, it will be created.
X:\cscript ESC.wsf -l 0 -$ -ow STDOUT original1.js original2.js Subject 'original1.js' and 'original2.js' for variable substitution, but perform no comment or whitespace removal. Redirect output to STDOUT instead of writing to file.
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js Crunch 'original.js' using variable substitution and remove any occurance of whitespace (where permitted...) and save it as 'crunched.js' (equals -l 3 -$)
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js > verbose.txt Crunch 'original.js' at level 4 and save the verbose output to verbose.txt
ESC.wsf
<?xml version="1.0"?>
<!-- Generated by Soya.IO.WSFFactory v0.95 [Tue, 28 Feb 2006 21:22:15 UTC] -->
<package>
<job>
<?job error="false" debug="false" ?>
<resource id="about">
-----------------------------------------------------------------------------
ESC (ECMAScript Cruncher)
* Version : 1.14
* Date : 2006-02-28 22:22:15 [+0100]
* License : GNU GPL 2 (http://www.gnu.org/copyleft/gpl.txt)
* Copyright (C) 2001-2006 Thomas Loo <tloo@saltstorm.net>
---------------------------------------------------------------------------
ESC is an ECMAScript(*) pre-processor enabling an unlimited number of
external scripts to be compressed/crunched into tight, bandwidth-optimized
packages. ESC supports compressing of external sources only. Trying to
process scripts inlined in HTML, ASP, PHP or equivalent pages are NOT
recommended with this version of ESC. This feature might be added in a
future version. Type "cscript ESC.wsf -help" for usage instructions.
ESC is built using components from the Soya Scripting API 1.0.0-b10,
a uni-host/cross-browser ECMAScript compliant class-library distributed
freely under the terms of the BSD License. The Soya Scripting API,
'lib-soya' and the Soya SDK can be found at http://www.saltstorm.net/
---------------------------------------------------------------------------
* ECMAScript is the international standard for javascript.
-----------------------------------------------------------------------------
</resource>
<resource id="copyright">
-----------------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-----------------------------------------------------------------------------
</resource>
<resource id="usage">
------------------------------------------------------------------------------
Usage: cscript ESC.wsf -l [0-4] -ow output.js foo.js bar.js C:\scripts\baz...
-----------------------------------------------------------------------------
-a [-about] : Description page
-c [-copyright] : Copyright/license notice
-e [-example] : Examples of usage
-h [-help] : This help-screen
-----------------------------------------------------------------------------
-l [-level] [01(2)34] : [optional] Set crunch-level (4 sets -$ on)
-s [-silent] : [optional] Run silent, nada stdout
-v [-verbose] : [optional] Run in verbose mode
-$ : [optional] Activate variable-substitution engine
-----------------------------------------------------------------------------
-oa <filename> : Target filename for appending
-ow <filename> : Target filename for writing
-ow STDOUT : Write stream to STDOUT
-----------------------------------------------------------------------------
<input-file(s)> : [required]
file(s) and/or directories containing scripts to crunch...
(paths containing spaces must be quoted)
</resource>
<resource id="example">
-----------------------------------------------------------------------------
Examples of usage.
Crunch 'original1.js','original2.js' and 'original3.js' at
level 2 (default) and save the output as 'crunched.js'.
Any previous file named 'crunched.js' will be overwritten.
X:\cscript ESC.wsf -ow crunched.js original1.js original2.js original3.js
---------------------------------------------------------------------------
Grab all scriptfiles (.js) in directory 'C:\script-directory' and crunch
them at level 1 (comment and empty line removal only) and append the result
to 'crunched.js'. If 'crunched.js' doesn't exist, it will be created.
X:\cscript ESC.wsf -l 1 -oa crunched.js C:\script-directory
---------------------------------------------------------------------------
Subject 'original1.js' and 'original2.js' for variable substitution,
but perform no comment or whitespace removal.
Redirect output to STDOUT instead of writing to file.
X:\cscript ESC.wsf -l 0 -$ -ow STDOUT original1.js original2.js
---------------------------------------------------------------------------
Crunch 'original.js' using variable substitution and remove
any occurance of whitespace (where permitted...)
and save it as 'crunched.js' (equals -l 3 -$)
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js
---------------------------------------------------------------------------
Try 'ESC.wsf -help' for information about available run-time directives.
-----------------------------------------------------------------------------
</resource>
<resource id="wscript">
ESC must be run from a DOS command prompt under
cscript.exe. Do you want to switch host and have
ESC bring up a helpscreen ?
</resource>
<resource id="jscript">
ESC needs JScript 5.5 or higher to score...
You need to update your version of JScript to run ESC.
Read the 'Requirements' section in the manual for information
how to obtain and install the latest version of Microsofts
'Windows Script' package.
</resource>
<resource id="common.map">
Anchor
ActiveXObject
Call
Closure
Components
Dictionary
Document
DOMParser
Embed
EvalError
Event
Form
Global
HttpCookie
Image
JavaArray
JavaClass
JavaMethod
JavaObject
JavaPackage
Layer
MimeType
MimeTypeArray
Option
Url
Packages
Plugin
PluginArray
Popup
RangeError
ReferenceError
TypeError
StyleClass
StyleSelector
SyntaxError
TypeError
WScript
URIError
XMLHttpRequest
XMLSerializer
XPathEvaluator
XSLTDocument
XSLTProcessor
Attr
CDATASection
CharacterData
Comment
CSS2Properties
DOMException
DOMImplementation
DocumentType
Element
EntityReference
EvalError
NamedNodeMap
Node
NodeList
Notation
ProcessingInstruction
Text
HTMLElement
HTMLDocument
HTMLCollection
HTMLHtmlElement
HTMLHeadElement
HTMLLinkElement
HTMLTitleElement
HTMLMetaElement
HTMLBaseElement
HTMLIsIndexElement
HTMLStyleElement
HTMLBodyElement
HTMLFormElement
HTMLSelectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLInputElement
HTMLTextAreaElement
HTMLButtonElement
HTMLLabelElement
HTMLFieldSetElement
HTMLLegendElement
HTMLUListElement
HTMLOListElement
HTMLDListElement
HTMLDirectoryElement
HTMLMenuElement
HTMLLIElement
HTMLBlockquoteElement
HTMLDivElement
HTMLParagraphElement
HTMLHeadingElement
HTMLQuoteElement
HTMLPreElement
HTMLBRElement
HTMLBaseFontElement
HTMLFontElement
HTMLHRElement
HTMLModElement
HTMLAnchorElement
HTMLImageElement
HTMLObjectElement
HTMLParamElement
HTMLAppletElement
HTMLMapElement
HTMLAreaElement
HTMLScriptElement
HTMLTableElement
HTMLTableCaptionElement
HTMLTableColElement
HTMLTableSectionElement
HTMLTableRowElement
HTMLTableCellElement
HTMLFrameSetElement
HTMLFrameElement
HTMLIFrameElement
_newEnum
alert
atob
attachEvent
back
btoa
captureEvents
clearTimeout
clearInterval
close
CollectGarbage
confirm
createEventObject
createPopup
decodeURI
decodeURIComponent
detachEvent
dump
encodeURI
encodeURIComponent
escape
eval
execScript
find
forward
frameElement
getAttention
GetAttention
getClass
getComputedStyle
getResource
GetObject
home
isFinite
isNaN
moveBy
moveTo
open
openDialog
parseInt
parseFloat
print
prompt
releaseEvents
resizeBy
resizeTo
ScriptEngine
ScriptEngineMajorVersion
ScriptEngineMinorVersion
ScriptEngineBuildVersion
scroll
scrollBy
scrollByLines
scrollByPages
scrollIntoView
scrollTo
setCursor
setInterval
setTimeout
showHelp
showModalDialog
showModelessDialog
sizeToContent
stop
taint
toString
updateCommands
unescape
untaint
valueOf
_content
appCore
arguments
arity
callee
caller
clientInformation
clipboardData
closed
constructor
controllers
crypto
debug
defaultStatus
directories
document
element
event
external
history
forward
frames
Infinity
innerHeight
innerWidth
java
length
loading
location
locationbar
name
menubar
navigator
netscape
offscreenBuffering
opener
opera
outerHeight
outerWidth
pageXOffset
pageYOffset
parent
personalbar
pkcs11
prompter
prototype
returnValue
screen
screenLeft
screenTop
screenX
screenY
scrollX
scrollY
scrollbars
self
sidebar
status
statusbar
style
sun
title
toolbar
top
window
onafterprint
onbeforeprint
onbeforeunload
onblur
onchange
onclick
onclose
onerror
onfocus
onhelp
onload
onresize
onreset
onscroll
onselect
onunload
onmousedown
onmouseup
onmouseover
onmouseout
onkeydown
onkeyup
onkeypress
onmousemove
onsubmit
onreset
onchange
onselect
onclose
onabort
onerror
onpaint
ondragdrop
Soya
BOOTSTRAP
</resource>
<resource id="core.map">
abstract
break
continue
const
class
catch
case
debugger
default
double
delete
do
enum
extends
else
function
finally
float
false
for
get
instanceof
implements
import
int
in
if
long
null
new
protected
private
package
public
return
switch
static
super
set
typeof
throw
true
this
try
undefined
void
var
while
with
getter
setter
__defineGetter__
__defineSetter__
end
elif
cc_on
_win32
_win16
_mac
_alpha
_x86
_mc680x0
_PowerPC
_jscript
_jscript_build
_jscript_version
Array
Boolean
Date
Enumerator
Error
Function
Math
Number
Object
RegExp
String
VBArray
</resource>
<script language="JScript">
<![CDATA[
/*** <POD [ESCtool] (Soya/1.0.0-b10; crlvl:2/1; Tue, 28 Feb 2006 21:22:16 UTC)> ***/
/**
Proving that ESC actually can handle name-mangling and as a general self-sanity
check, ESC has been used to compress itself along with other required Soya-beans
while creating the package you see below. To examine these beans in a more human
readable form, get the latest distribution of the Soya API.
**/
function Soya_API($h)
{
this.name='Soya';
this.version='1.0.0-b10';
this.type='static';
this.debug=0;
this.host=$h;
this.libPath='/lib-soya/';
this.podPath='pods';
this.resourcePath='resources';
this.attachBean=$a;
this.declareBean=$b;
this.registerBean=$c;
this.BeanPrototype=Soya_BeanPrototype;
this.beans=new Object();
this.beans.all=new Array();
Soya_Loader.prototype=new this.BeanPrototype();
this.Loader=new Object();
this.Loader.orphans=new Array();
this.Loader.callbacks=new Object();
this.declareBean('Soya.BeanPrototype',null,this.name,false,true);
}
function Soya_VirtualBean(){}
function Soya_BeanPrototype(){
this.name='Soya.BeanPrototype';
}
function $a($i){
if(!$i.virtual){
eval($i.mutexName).prototype=$i;
eval($i.name+'='+(!$i.constructable?'new ':' ')+
$i.mutexName+(!$i.constructable?'()':''));
}
else eval($i.name+'=this.beans["'+$i.name+'"]');
$i.complete=true;
if(this.Loader&&this.Loader.callbacks[$i.name])
this.Loader.callbacks[$i.name](eval($i.name));
}
function $b($j,$k,$l,$m,$n){
var $o=$k?new this.BeanPrototype():new Soya_VirtualBean();
$o.name=$j;
$o.mutexName=$k||'Soya_VirtualBean';
$o.parentName=$l;
$o.iid=0;
$o.stack=new Array();
$o.complete=Boolean($n);
$o.constructable=($k&&!$m);
$o.virtual=!$k;
return(this.beans[$j]=this.beans.all[this.beans.all.length]=$o);
}
function $c($j,$m,$p,i){
var $q;
var $r=$j.split('\x2e');
var $k=$r.join('\x5f');
if(!this.beans[$j]){
if($p){
var $s='';
$q=$r[0];
for(i=1;i<$r.length-1;i++){
$s+=$q;
$q+=('\x2e'+$r[i]);
if(i<=$p&&!this.beans[$q])
this.attachBean(this.declareBean($q,null,$s,true,true));
}
}
$r.length-=$p?$p:1;
$q=$r.join('\x2e');
this.declareBean($j,$k,$q,$m);
if($r.length>1&&!this.beans[$q])
this.Loader.orphans[this.Loader.orphans.length]=this.beans[$j];
else{
this.attachBean(this.beans[$j]);
var $t=new Array();
for(i=0;i<this.Loader.orphans.length;i++)
if(this.Loader.orphans[i].parentName==$j)
this.attachBean(this.Loader.orphans[i]);
else $t[$t.length]=this.Loader.orphans[i];
this.Loader.orphans=$t;
}
}
return Boolean(i)
}
function $d($u){
this.getResourcePath=Function('sName',
"return(Soya.libPath + Soya.resourcePath + '/' + (sName||this.name).split('.').join('/') + '/')");
this.getClass=Function('sName','return eval(Soya.beans[sName || this.name].mutexName)');
this.toString=Function("return('[object ' + (this.name || 'noname') + ']')");
this.getBeanPath=Function('sName',
"return(Soya.libPath + (sName||this.name).split('.').join('/') + '.js')");
this.type='static';
if(!$u){
this.finalize=$f;
this.initialize=$e;
}
}
function $e($v){
this.iid=this.getClass().prototype.iid++;
if(this.stackable)
this.stack[this.iid]=this;
if(!Soya.beans[this.name].initialized){
$v=$v||
Soya.host[Soya.beans[this.name].mutexName+'_initialize'];
if(typeof($v)=='function')
Soya.beans[this.name].initialized=!$v(this.getClass(),this);
}
}
function $f($w){
$w=$w||
Soya.host[Soya.beans[this.name].mutexName+'_finalize'];
if(typeof($w)=='function')
$w(this.getClass(),this);
}
function Soya_Loader(){};
function $g($x,$y,$z){
if(!Soya.fso)
Soya.fso=new ActiveXObject('Scripting.FilesystemObject');
if(Soya.fso.FileExists($x)){
var $i=Soya.fso.GetFile($x),
$A=Soya.fso.OpenTextFile($i.Path),
$B=$A.Read($z||$i.Size);
$A.Close();
return $B;
}
else if(!$y)
return(WScript.Echo(this.name+' '+Soya.version+
'> File Not found: '+$x),WScript.Quit(99));
else return '';
}
Soya_BeanPrototype.prototype=new $d(0);
Soya_VirtualBean.prototype=new $d(1);
Soya_API.prototype=new $d(1);
var Soya=new Soya_API(this);
if(typeof(BOOTSTRAP)=='function')BOOTSTRAP(Soya);
function Soya_Common()
{
this.name='Soya.Common';
this.type='static';
this.version='1.03';
this.dependencies=[];
this.destroy=$E;
this.makeFunction=$G;
this.typematch=$F;
this.getObject=$C;
this.$ih=$H;
Function.prototype.getArguments=$D;
Soya.BeanPrototype.prototype.Extends=
Function('oBean','bOvr','Soya.Common.$ih(oBean, this, bOvr)');
Soya.BeanPrototype.prototype.Implements=
Function('oBean','bOvr','Soya.Common.$ih(this, oBean, bOvr)');
this.interfaces=new Object();
this.interfaces['Scripting.FilesystemObject']=Soya.fso;
}
function $C($I,$J){
if(typeof(this.interfaces[$I])=='undefined'){
if(typeof ActiveXObject=='function'){
Soya.host.msieax=null;
if(typeof Error=='function')
eval('try{Soya.host.msieax=new ActiveXObject("'+$I+'")}catch(e){}');
else{
var $K=String("on error resume next\nself.msieax=CreateObject('"+$I+"'))");
self.execScript($K,'vbscript');
}
if(!$J)
return Soya.host.msieax;
this.interfaces[$I]=Soya.host.msieax;
}
}
return this.interfaces[$I]||void(0);
}
function $D($L){
var $M=[],
$N=(isNaN($L)||$L<1)?
0:Math.min($L,this.arguments.length);
for(;$N<this.arguments.length;$N++)
$M[$M.length]=this.arguments[$N];
return $M;
}
function $E($O){
if($O!=null&&typeof($O)=='object')
for(var $P in $O){
if(typeof($O[$P])=='object'&&$O[$P])
if($O[$P].constructor&&!$O[$P].style){
this.destroy($O[$P]);
delete($O[$P]);
}
else $O[$P]=null;
}
}
function $F($Q,$R){
var $S;
switch(typeof($Q)){
case 'number':$S=2;break;
case 'boolean':$S=4;break;
case 'string':$S=8;break;
case 'function':$S=16;break;
case 'object':$S=32;break;
default:$S=1;break;
}
return Boolean($S&($R||62));
}
function $G($T){
if($T&&this.typematch($T,16))
return $T;
else return Function(($T&&this.typematch($T,8))?$T:'');
}
function $H($U,$V,$W){
for(var $P in $U)
if($P!='name'&&(!$W||typeof($V[$P])=='undefined'))
$V[$P]=$U[$P];
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.Common',true);
function Soya_WSH()
{
this.name='Soya.WSH';
this.type='static';
this.version='0.88';
this.dependencies=['Soya.Common','Soya.WSH.Registry'];
this.osInfo={};
this.arguments={length:0};
this.$09=function($00)
{return $00.length<2?$00:$00.replace(/^\\-/,'-').replace(/\\{2}/g,'\\')};
this.getArgument=function($01){return(this.arguments[$01]||"")}
this.getArguments=$X;
this.getOSInfo=$Z;
this.getShell=$Y;
}
function $X(){
if(!this.arguments.length&&WScript.Arguments.length){
var i,$02,$03=[],$04=new RegExp('^-+');
for(i=0;i<WScript.Arguments.length;i++)
$03[$03.length]=WScript.Arguments.item(i);
for(i=0;i<$03.length;i++){
$02=$03[i].replace($04,'-');
if($02.length>1&&$04.test($02)){
if(typeof $03[i+1]!='undefined'&&!$04.test($03[i+1]))
this.arguments[this.$09($02.replace($04,''))]=
this.$09($03[1+(i++)]);
else this.arguments[this.$09($02.replace($04,''))]=1;
};
else if($02.length)
this.arguments[this.arguments.length++]=this.$09($03[i]);
}
}
return this.arguments;
}
function $Y(){
if(!this.shell)
this.shell=Soya.Common.getObject('WScript.Shell');
return this.shell;
}
function $Z(){
if(this.osInfo.$0a)
return this.osInfo;
var $05=Soya.Common.getObject('Scripting.FilesystemObject'),
$06=this.getShell().ExpandEnvironmentStrings("%SYSTEMROOT%");
this.osInfo.MSIEVersion=Soya.WSH.Registry.regRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\Version');
this.osInfo.NETVersion=Soya.WSH.Registry.regRead('HKLM\SOFTWARE\Microsoft\.NETFramework\\Version')||-1;
this.osInfo.SPVersion=Soya.WSH.Registry.regRead('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CSDVersion')||-1;
this.osInfo.JSVersion=parseFloat(ScriptEngineMajorVersion()+'.'+ScriptEngineMinorVersion());
if($05.FolderExists($06+'\\system32'))
$07=$05.GetFileVersion($06+'\\system32\\kernel32.dll');
else if($05.FolderExists($06+'\\system'))
$07=$05.GetFileVersion($06+'\\system\\kernel32.dll');
if($07){
/^(\d)\.(\d+)\.(\d+)\.\d+$/.test($07);
this.osInfo.majorVersion=parseInt(RegExp.$1);
this.osInfo.minorVersion=parseInt(RegExp.$2,10);
this.osInfo.buildVersion=parseInt(RegExp.$3,10);
this.osInfo.version=$07;
var $08={
'4.00.950':'Win95',
'4.00.1111':'Win95 OSR2',
'4.00.1381':'WinNT',
'4.10.1998':'Win98',
'4.10.2222':'Win98SE',
'4.90.3000':'WinME',
'5.0.2195':'Win2K',
'5.10.2600':'WinXP'
};
this.osInfo.name=$08[$07.replace(/\.\d+$/,'')]||'unknown';
}
this.osInfo.$0a=1;
return this.osInfo;
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.WSH',true);
function Soya_Saltstorm_ESC($0t,$0u,$0v,$y)
{
this.name='Soya.Saltstorm.ESC';
this.version='1.14';
this.type='constructor';
this.dependencies=['Soya.Common','Soya.ECMA.Array'];
this.resourcePath=$0v||'';
this.crunchLevel=$0t||2;
this.substitute=false;
this.verbose=$0u;
this.silent=($y||typeof window=='object');
this.initialize();
this.flush();
}
function Soya_Saltstorm_ESC_initialize($0w,$0x){
$0y=$0x;
var $0z="(?:\"{2}|'{2}|\".*?.\"|'.*?.'|\\/(?!\\*|\\/)..*?\\/)";
var $0A="[-!%&;<=>~:\\/\\^\\+\\|\\,\\(\\)\\*\\?\\[\\]\\{\\}]+";
var $0B="\\/\\*(?!@).(?:.|\\n)*?\\*\\/|\\/\\/.*";
var $0C="\".*?.\"|'.*?.'|\\s*\\/{2,}.*\\n";
var $0D="\\}(?!catch|else|while)([^;,\\|\\.\\]\\)\\}])";
with($0w){
prototype.fileFilter=new RegExp('.+\\\\(?!$|_)\\w*\\.js$','i');
prototype.$1r=["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",9];
prototype.$1s={};
prototype.fso=Soya.Loader.fso||new ActiveXObject('Scripting.FilesystemObject');
prototype.core={};
prototype.bless={};
prototype.mangle={};
prototype.common={};
prototype.$1t=$g;
prototype.crunch=$0r;
prototype.flush=function(){this.buffer='';this.report=new $0c()};
prototype.getSubstitute=$0g;
prototype.loadMaps=$0d;
prototype.out=$0b;
prototype.load=$0e;
prototype.save=$0f;
prototype.getReport=$0s;
prototype.$1u=new RegExp("[$_]");
prototype.$1v=new RegExp("[^$\\w]","g");
prototype.$1w=new RegExp("^[\\x00\\.\"']");
prototype.$1x=new RegExp("\\s+$");
prototype.$1y=new RegExp("^\\s*\\W");
prototype.$1z=new RegExp("^[-\\\\+\"~'!]");
prototype.$1A=new RegExp("("+$0z+")|("+$0B+")","g");
prototype.$1B=new RegExp("("+$0C+")","g");
prototype.$1C=new RegExp("("+$0z+")|(\\r?\\n\\s+)|(\\x20{2,})","g");
prototype.$1D=new RegExp("("+$0z+")|(\\w+)?\\s+("+$0A+")","g");
prototype.$1E=new RegExp("("+$0z+")|("+$0A+")[ \\t]+","g");
prototype.$1F=new RegExp("("+$0z+")|function[\\n\\s]+([$\\w]+)","g");
prototype.$1G=new RegExp("("+$0z+")|("+$0B+")|(\\W[\\n\\s]*?[$\\w]+)\\b","gm");
prototype.$1H=new RegExp("("+$0z+")|(\\x00)|\\.[\\n\\s]*?([$_][$\\w]{3,})","g");
prototype.$1I=new RegExp("("+$0z+")|(\\S)\\s*[\\r\\n]+\\s*(\\S)","g");
prototype.$1J=new RegExp("[$\\w][$\\w]");
prototype.$1K=new RegExp("("+$0D+")","g");
}
}
function $0b($0E,$0F){
if(!this.silent){
var $0G=String((!$0F?'ESC> ':'')+($0E||''));
WScript.Echo($0G);
}
}
function $0c(){
this.scripts=[];
this.rawSize=
this.crunchedSize=
this.elapsedTime=0;
}
function $0d(){
if(this.$1L)
return;
var $0H,$0I,$0J,$0K,$0L;
for(var i=0;i<arguments.length;i++){
$0H=arguments[i].replace(/\W.+$/,'');
try{
$0J=getResource(arguments[i]).split(/\r?\n/g)||[];
for(var j=0;j<$0J.length;j++)
if($0J[j].length&&!$0y.$1y.test($0J[j]))
Soya_Saltstorm_ESC.prototype[$0H][$0J[j].replace($0y.$1x,'')]=1;
if(this.verbose)
this.out('Parsed map "'+$0H+'", '+$0J.length+' entries.')
}
catch($0M){
if($0M)
$0J=null;
}
if($0J)
continue;
else $0I=this.fso.BuildPath(this.resourcePath,arguments[i]);
if(/^common|core/.test(arguments[i])&&!this.fso.FileExists($0I)){
this.out('Couldn\'t $0N $0O:'+
this.fso.GetAbsolutePathName($0I));
return WScript.Quit(99);
}
else if(typeof this[$0H]!='object'){
this.out('Unrecognized mapname : '+$0H);
return WScript.Quit(99);
}
else if(this.fso.FileExists($0I)){
$0J=this.fso.OpenTextFile($0I);
$0L=0;
while(!$0J.AtEndOfStream){
$0K=$0J.ReadLine();
if($0K.length&&!$0y.$1y.test($0K))
Soya_Saltstorm_ESC.prototype[$0H][$0K.replace($0y.$1x,'')]=++$0L;
}
$0J.Close();
Soya_Saltstorm_ESC.prototype[$0H].length=$0L;
if(this.verbose)
this.out('Loaded map "'+$0H+'", '+$0L+' entries. ['+$0I+']');
}
}
this.$1L=1;
}
function $0e(){
var i,$0P,$0Q,$0R,$0S=[];
for(i=0;i<arguments.length;i++){
if(arguments[i]&&this.fso.FolderExists(arguments[i])){
$0R=new Enumerator(this.fso.GetFolder(arguments[i]).SubFolders);
for(;!$0R.atEnd();$0R.moveNext())
arguments[arguments.length++]=$0R.item().Path;
$0R=new Enumerator(this.fso.GetFolder(arguments[i]).Files);
for(;!$0R.atEnd();$0R.moveNext())
if($0R.item().Size&&this.fileFilter.test($0R.item().Path))
$0S.push($0R.item().Path);
}
else if(arguments[i])
$0S.push(arguments[i]);
}
for(i=0;i<$0S.length;i++){
if(!this.fso.FileExists($0S[i])){
this.out('Couldn\'t $0N $0T:"' + this.fso.GetAbsolutePathName(aLoadQueue[i]) + '"');
return WScript.Quit(99);
}
else if(this.verbose)
this.out('Loading script :"'+this.fso.GetAbsolutePathName($0S[i])+'"');
$0Q=this.fso.GetFile($0S[i]);
this.buffer+=(this.report.scripts.length?'\r\n':'');
this.buffer+=this.$1t($0Q.Path,true);
this.report.scripts.push(
$0Q.Path+' ('+($0Q.Size/1024).toFixed(2)+' kb)');
}
return $0S.length;
}
function $0f($0U,$0V){
var $0W;
if(!$0U){
this.out('Need an output filename!');
return WScript.Quit(99);
}
else if(this.fso.FolderExists($0U)){
this.out('Need an output filename, "'+
this.fso.GetAbsolutePathName($0U)+'" is a folder.');
return WScript.Quit(99);
}
this.outFile=this.fso.GetAbsolutePathName($0U);
this.outMode=$0V?'Writing':'Appending';
$0W=this.fso.OpenTextFile(this.outFile,($0V?2:8),true);
$0W.WriteLine(this.buffer);
$0W.Close();
}
function $0g($0X){
if(!this.$1s[$0X]){
var k=1;
while(k<5){
this.$1r[k]++;
if(this.$1r[k]&&!(this.$1r[k]%62)){
k++;
if(this.$1r.length==k)
this.$1r[k]=-1;
}
else break;
}
this.$1s[$0X]='$';
for(k=this.$1r.length-1;k>0;k--)
this.$1s[$0X]+=this.$1r[0].charAt(this.$1r[k]%62);
if(this.verbose)
this.out('Substituting ['+this.$1s[$0X]+'] -> ['+$0X+']');
}
return this.$1s[$0X];
}
function $0h($0Y,$0Z,$10){
if(typeof $10!='undefined')
return '';
else return $0Y;
}
function $0i($0Y,$11){
if(typeof $11!='undefined'&&/^\s+/.test($11))
return '\r\n';
else return $0Y;
}
function $0j($0Y,$12,$13){
if(typeof $12!='undefined')
return $0Y;
else if($13&&$13.length>2&&
($0y.mangle[$13]||$0y.$1u.test($13.charAt(0))))
$13=$0y.getSubstitute($13);
else Soya_Saltstorm_ESC.prototype.bless[$13]=1;
return String('function \x00'+$13);
}
function $0k($0Y,$12,$14,$15){
if(typeof $12=='undefined'&&typeof $14=='undefined'&&typeof $15=='string'){
$15=$15.replace(/\s+/g,'');
if(!$0y.$1w.test($15)&&isNaN(parseInt($15.substr(1),10))){
$15=$15.replace($0y.$1v,'');
if($15.length>2&&!$0y.core[$15]&&!$0y.common[$15]&&
!$0y.bless[$15]&&($0y.mangle[$15]||!$0y.mangle.length))
return $0Y.replace($15,$0y.getSubstitute($15));
}
}
return $0Y;
}
function $0l($0Y,$12,$16,$P){
if(typeof $P=='string')
return(!$0y.core[$P]&&!$0y.common[$P]&&!$0y.bless[$P])?
String('.'+$0y.getSubstitute($P)):$0Y;
else if(typeof $12!='undefined')
return $0Y;
else return '';
}
function $0m($0Y,$12,$17,$18,$19){
if(typeof $12!='undefined')
return $0Y;
else if(typeof $17!='undefined')
return '\r\n';
else if(typeof $18!='undefined')
return ' ';
else return '';
}
function $0n($0Y,$12,$1a,$1b){
if(typeof $12=='undefined'){
if(!$0y.$1z.test($1b)||!$1a||!$0y.core[$1a])
return($1a||'')+$1b;
else return $0Y;
}
else return $12;
}
function $0o($0Y,$12,$1b){
if(typeof $12!='undefined')
return $0Y;
else return $1b;
}
function $0p($0Y,$1c,$1d){
return('};'+$1d);
}
function $0q($0Y,$12,$1e,$1f){
if(typeof $1e=='undefined')
return $0Y;
var $1g=($0y.$1J.test($1e+$1f))?' ':'';
return $1e+$1g+$1f;
}
function $0r($1h,$0t,$1i){
var $B=(typeof $1h=='string')?$1h:this.buffer;
this.loadMaps('core.map','common.map','bless.map','mangle.map');
if(!this.buffer.length&&!$1h)
return String();
else if(typeof $0t=='number')
this.crunchLevel=$0t;
var $1j=(new Date()).getTime()-1;
var $1k=$B.length;
this.report.rawSize+=$B.length;
if(this.crunchLevel>=1){
$B=$B.replace(this.$1A,$0h)
.replace(this.$1B,$0i)
.replace(/\s*\r?\n/g,'\r\n');
if(this.verbose)
this.out('Removing comments, empty lines and trailing whitespace, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.crunchLevel>=2){
$B=$B.replace(this.$1C,$0m);
if(this.verbose)
this.out('Removing tabs and spaces, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
$B=$B.replace(this.$1D,$0n);
if(this.verbose)
this.out('Removing spaces left to operators, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
$B=$B.replace(this.$1E,$0o);
if(this.verbose)
this.out('Removing spaces right to operators, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.substitute||$1i||this.crunchLevel>=4){
$B=$B.replace(this.$1F,$0j);
$B=$B.replace(this.$1G,$0k);
$B=$B.replace(this.$1H,$0l);
if(this.verbose)
this.out('Substitution summary, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.crunchLevel>=3){
$B=$B.replace(this.$1I,$0q);
$B=$B.replace(this.$1K,$0p);
$B+='\r\n';
if(this.verbose){
this.out('Removing newlines, saved '+
($1k-$B.length)+' bytes.');
this.out('',1);
}
}
if(typeof $1h=='string'){
this.report.crunchedSize+=$B.length;
this.buffer+=$B;
}
else{
this.buffer=$B;
this.report.crunchedSize=$B.length;
}
this.report.elapsedTime+=(new Date()).getTime()-$1j;
return this.buffer;
}
function $0s($1l){
var $1m=($1l||'\r\n'),
$1n=this.label?String($1m+this.label+$1m):'';
if(!this.report.elapsedTime){
$1n+='Nothing to report, yet...';
return(!$1o)?this.out($1n,1):$1n;
}
var $1p=Boolean(this.substitute||this.crunchLevel>=4),
$1q=this.report.rawSize-this.report.crunchedSize;
if(this.report.scripts.length){
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" Crunching script(s):\r\n\t * "+this.report.scripts.join("\r\n\t * ")+$1m;
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" "+(this.outMode||"Put")+" to : "+(this.outFile||"[buffer]")+" ("+
(this.report.crunchedSize/1024).toFixed(2)+" kb)"+$1m;
}
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" Processtime :\t"+(this.report.elapsedTime/1000).toFixed(3)+" secs"+$1m;
$1n+=" Crunch-level :\t"+this.crunchLevel+$1m;
$1n+=" Subst. engine :\t"+($1p?'On':'Off')+$1m;
if($1p)
$1n+=" Substitutions :\t"+(this.$1r[1]-9)+$1m;
$1n+=" Original size :\t"+(this.report.rawSize/1024).toFixed(2)+" kb"+$1m;
$1n+=" Crunched size :\t"+(this.report.crunchedSize/1024).toFixed(2)+" kb"+$1m;
$1n+=" Saving ratio :\t"+($1q/1024).toFixed(2)+" kb"+$1m;
$1n+=" -'' ''- (%) :\t"+(($1q/this.report.rawSize)*100).toFixed(2)+" %"+$1m;
$1n+="-----------------------------------------------------------------------------"+$1m;
return $1n;
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.Saltstorm.ESC',false,1);
/*** </POD> ***/
]]>
</script>
<script language="JScript">
<![CDATA[
/*
Command flow control script for ESC.wsf
Edited : 2005-02-06
*/
var oShell = WScript.CreateObject('WScript.Shell');
if(!oShell)
WScript.Quit(64);
// Do we have Jscript 5.5+ ?
else if(oShell && parseFloat(ScriptEngineMajorVersion() + '.' + ScriptEngineMinorVersion()) < 5.5)
oShell.Popup(getResource('jscript'), 64, WScript.ScriptName, 16), WScript.Quit(4);
// Is ESC executed under cscript ?
// if not let user select switching to cscript automagically.
else if(oShell && WScript.FullName.toLowerCase().indexOf('cscript') < 0){
if(oShell.Popup(getResource('wscript'), 64, WScript.ScriptName, 52) == 6)
oShell.Run('%comspec% /Q /K cscript //NoLogo ' + WScript.ScriptName + ' -a', 9);
WScript.Quit(3);
}
// get the cmdline arguments formatted in a nice manner.
var oArgs = Soya.WSH.getArguments();
// should we run in verbose-mode ?;
var bVerbose = Boolean(!oArgs.s && !oArgs.silent && (oArgs.v || oArgs.verbose));
// create an instance of the ESC object.
var esc = new Soya.Saltstorm.ESC(oArgs.l || oArgs.level, bVerbose);
esc.label = 'ESC (ECMAScript Cruncher) ' + esc.version +
'\r\nCopyright (C) 2001-2005 Thomas Loo <tloo@saltstorm.net>';
esc.resourcePath = esc.fso.GetParentFolderName(WScript.ScriptFullName || '.');
var sOutput = String(oArgs.oa || oArgs.ow || '');
if(oArgs.a || oArgs.about){
WScript.Echo(getResource('about'));
WScript.Quit(1);
}
else if(oArgs.c || oArgs.copyright){
WScript.Echo('\n' + esc.label + getResource('copyright'));
WScript.Quit(1);
}
else if(oArgs.e || oArgs.example){
WScript.Echo('\n' + esc.label + getResource('example'));
WScript.Quit(1);
}
// if there are options missing, print out the help table and quit.
else if((oArgs.h || oArgs.help) || !sOutput.length || !oArgs[0]){
WScript.Echo('\n' + esc.label + getResource('usage'));
WScript.Quit((oArgs.h || oArgs.help) ? 1 : 2);
}
// Wake up the variable substitution engine if option set (-$);
esc.substitute = Boolean(oArgs.$);
// load input files;
for(var i = 0; i < oArgs.length; i++)
esc.load(oArgs[i]);
// crunch baby, crunch!;
if(sOutput.toUpperCase() == 'STDOUT'){
esc.silent = true;
WScript.StdOut.Write(esc.crunch());
}
else if(sOutput.length){
esc.crunch();
esc.save(sOutput, Boolean(oArgs.ow));
// write report to stdout if not silence'd.
if(!oArgs.s && !oArgs.silent)
WScript.StdOut.Write(esc.getReport());
}
// Shutting down nicely..
WScript.Quit(0);
]]>
</script>
</job>
</package>
用法:
在 cmd下面输入的东西;
cscript ESC.wsf -l 3 -ow ../global.js global.js
上面是一个简单的例子:可以自己建一个bat文件放在当前目录下面
cscript ESC.wsf -l 压缩级别 -ow 。。/要压缩到那个目录 需要进行压缩的原js
1.
Level 0 :: No compression //没有处里
Level 1 :: Comment removal //删除掉注释
Level 3 :: Newline removal //删除掉新行
Level 4 :: Variable substitution //变量的替换
2.下图时所用到的参数:
-l 级别
-s
-v
-$
-oa 以追加的形式覆盖
-ow 以覆盖的形式覆盖
所用压缩包在附件 还有帮助文档
使用的例子见压缩包中的图片。
下载地址 http://xiazai.jb51.net/201003/yuanma/ESC.rar
Introduction
ESC is an ECMAScript pre-processor written in JScript, enabling an unlimited number of external scripts to be compressed/crunched into supertight, bandwidth-optimized packages. Featuring several compression-techniques such as comment removal, whitespace stripping, newline stripping and variable substitution ESC can reduce the overall size of your code with up to ~45%. Single, multiple scripts and even directories with scripts can be merged together at the compression level you decide. The processed output can later be appended or written to a file, or piped to another application for further processing via STDOUT. ESC do NOT support crunching of inline scripts. So any attempt passing HTML, ASP, JSP, PHP or other equivalent documents to ESC is done at your own risk. ESC supports four levels of compression, where a higher level equals higher compression. Beware though that levels >2 requires your code to be syntaxically perfect or ESC will punish you by producing a broken and useless output. The compression ratio should hit around 25% using the default compression level on a vanilla looking script, but results as high as ~45% can be achieved depending on the script's design / your style of writing code. ESC's compression engine is intelligent in the meaning that it has language syntax, statement and keyword awareness and it *knows* about native objects and members provided by the most common scripting hosts. This knowledgebase can easily be extended by pluggin in userdefined maps with additional information to further gain control of the crunching procedure. During processing following things are taken into account : String and RegExpression read-ahead
JScript Conditional compilation statements and variables
ECMA-262 Core language definitions (ECMAScript)
Intermediate DOM's (level 0) and DOM level 1
MS JScript specific objects/methods
Netscape/Mozilla/Opera specific objects/methods/properties
MS WSH (Windows Scripting Host) 1+ native objects
Crunching, level by level
Level 0 :: No compression
No compression done. Basically a content transfer/append from input(s) to output. This level is mainly used for tracking down problems occuring to scripts after been shoved through the variable substitution engine.
Level 1 :: Comment removal
ESC removes empty lines (\r?\n)+, single and multi-line and single-line comments (//..., /* ... */) and trailing whitespace. [ \t]+\r?\n
Level 2 :: Whitespace removal
Any occurance of space and tabs (\s\t\r) are removed from the infile(s). This is the default compression-level if none is supplied.
Level 3 :: Newline removal
Newlines (\r?\n) are removed. ESC do not like sloppy written code and will at this level punish you for it by producing a very tight, human unreadable, uninpretable chunk o' chars :) So remember, *ALWAYS* terminate your statements with semi-colons (';'). If you come from a C/C++ bg you have probably been taught this the hard way by an evercroaking compiler. If not for getting your script thru ESC, so start doing it anyway for good ol' programming style.
Level 4 :: Variable substitution
(variable substitution mode, identical to options '-l 3 -$') Additionally to level 3, ESC will run your script(s) through the variable substitution engine. This will certainly break your scripts at the first try, but with a little fiddling around and once you understand how the substitution scheme works, this thing rule since it will save you another extra 5-20% bytewise depending on your coding style. Variable-names less than 3 chars are not affected. Before you try running ESC with variable substitution enabled, I advice you to carefully read the other sections in this manual about the pros and cons, thinking session-dependencies and the known caveats of variable crunching with ESC. Your specific situation in terms of namespaces, shared variables or the design/architecture of your scripts may make it difficult, even impossible to combine with this technique whereas you'll have to stick with level 3.
Commandline options |
There are a set of options available to provide full control of how you want your source files treated. This list is also available by running ESC with the -help option, but I'll try to explain some of them here more indepth. |
|
----------------------------------------------------------- Usage : ESC.wsf -l [0-4] -ow output.js foo.js bar.js C:\scripts\baz ----------------------------------------------------------- -a [-about] : Description page -c [-copyright] : Copyright/license notice -e [-example] : Examples of usage -h [-help] : This help-screen ----------------------------------------------------------- -l [-level] [01(2)34] : [optional] Set crunch-level (4 sets -$ on) -s [-silent] : [optional] Run silent, nada stdout -v [-verbose] : [optional] Run in verbose mode -$ : [optional] Activate variable-substitution engine ----------------------------------------------------------- -oa <filename> : Target filename for appending -ow <filename> : Target filename for writing -ow STDOUT : Write stream to STDOUT ----------------------------------------------------------- <input-file(s)> : [required] file(s) and/or directories containing scripts to crunch... (If filenames contains spaces, they must be quoted) |
Examples of usage
X:\cscript ESC.wsf -ow crunched.js original1.js original2.js original3.js Crunch 'original1.js','original2.js' and 'original3.js' at level 2 (default) and save the output as 'crunched.js'. Any previous file named 'crunched.js' will be overwritten.
X:\cscript ESC.wsf -l 1 -oa crunched.js C:\script-directory Grab all scriptfiles (.js) in directory 'C:\script-directory', crunch them at level 1 (comment and empty line removal only) and append the result to 'crunched.js'. If 'crunched.js' doesn't exist, it will be created.
X:\cscript ESC.wsf -l 0 -$ -ow STDOUT original1.js original2.js Subject 'original1.js' and 'original2.js' for variable substitution, but perform no comment or whitespace removal. Redirect output to STDOUT instead of writing to file.
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js Crunch 'original.js' using variable substitution and remove any occurance of whitespace (where permitted...) and save it as 'crunched.js' (equals -l 3 -$)
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js > verbose.txt Crunch 'original.js' at level 4 and save the verbose output to verbose.txt
ESC.wsf
复制代码 代码如下:
<?xml version="1.0"?>
<!-- Generated by Soya.IO.WSFFactory v0.95 [Tue, 28 Feb 2006 21:22:15 UTC] -->
<package>
<job>
<?job error="false" debug="false" ?>
<resource id="about">
-----------------------------------------------------------------------------
ESC (ECMAScript Cruncher)
* Version : 1.14
* Date : 2006-02-28 22:22:15 [+0100]
* License : GNU GPL 2 (http://www.gnu.org/copyleft/gpl.txt)
* Copyright (C) 2001-2006 Thomas Loo <tloo@saltstorm.net>
---------------------------------------------------------------------------
ESC is an ECMAScript(*) pre-processor enabling an unlimited number of
external scripts to be compressed/crunched into tight, bandwidth-optimized
packages. ESC supports compressing of external sources only. Trying to
process scripts inlined in HTML, ASP, PHP or equivalent pages are NOT
recommended with this version of ESC. This feature might be added in a
future version. Type "cscript ESC.wsf -help" for usage instructions.
ESC is built using components from the Soya Scripting API 1.0.0-b10,
a uni-host/cross-browser ECMAScript compliant class-library distributed
freely under the terms of the BSD License. The Soya Scripting API,
'lib-soya' and the Soya SDK can be found at http://www.saltstorm.net/
---------------------------------------------------------------------------
* ECMAScript is the international standard for javascript.
-----------------------------------------------------------------------------
</resource>
<resource id="copyright">
-----------------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-----------------------------------------------------------------------------
</resource>
<resource id="usage">
------------------------------------------------------------------------------
Usage: cscript ESC.wsf -l [0-4] -ow output.js foo.js bar.js C:\scripts\baz...
-----------------------------------------------------------------------------
-a [-about] : Description page
-c [-copyright] : Copyright/license notice
-e [-example] : Examples of usage
-h [-help] : This help-screen
-----------------------------------------------------------------------------
-l [-level] [01(2)34] : [optional] Set crunch-level (4 sets -$ on)
-s [-silent] : [optional] Run silent, nada stdout
-v [-verbose] : [optional] Run in verbose mode
-$ : [optional] Activate variable-substitution engine
-----------------------------------------------------------------------------
-oa <filename> : Target filename for appending
-ow <filename> : Target filename for writing
-ow STDOUT : Write stream to STDOUT
-----------------------------------------------------------------------------
<input-file(s)> : [required]
file(s) and/or directories containing scripts to crunch...
(paths containing spaces must be quoted)
</resource>
<resource id="example">
-----------------------------------------------------------------------------
Examples of usage.
Crunch 'original1.js','original2.js' and 'original3.js' at
level 2 (default) and save the output as 'crunched.js'.
Any previous file named 'crunched.js' will be overwritten.
X:\cscript ESC.wsf -ow crunched.js original1.js original2.js original3.js
---------------------------------------------------------------------------
Grab all scriptfiles (.js) in directory 'C:\script-directory' and crunch
them at level 1 (comment and empty line removal only) and append the result
to 'crunched.js'. If 'crunched.js' doesn't exist, it will be created.
X:\cscript ESC.wsf -l 1 -oa crunched.js C:\script-directory
---------------------------------------------------------------------------
Subject 'original1.js' and 'original2.js' for variable substitution,
but perform no comment or whitespace removal.
Redirect output to STDOUT instead of writing to file.
X:\cscript ESC.wsf -l 0 -$ -ow STDOUT original1.js original2.js
---------------------------------------------------------------------------
Crunch 'original.js' using variable substitution and remove
any occurance of whitespace (where permitted...)
and save it as 'crunched.js' (equals -l 3 -$)
X:\cscript ESC.wsf -l 4 -ow crunched.js original.js
---------------------------------------------------------------------------
Try 'ESC.wsf -help' for information about available run-time directives.
-----------------------------------------------------------------------------
</resource>
<resource id="wscript">
ESC must be run from a DOS command prompt under
cscript.exe. Do you want to switch host and have
ESC bring up a helpscreen ?
</resource>
<resource id="jscript">
ESC needs JScript 5.5 or higher to score...
You need to update your version of JScript to run ESC.
Read the 'Requirements' section in the manual for information
how to obtain and install the latest version of Microsofts
'Windows Script' package.
</resource>
<resource id="common.map">
Anchor
ActiveXObject
Call
Closure
Components
Dictionary
Document
DOMParser
Embed
EvalError
Event
Form
Global
HttpCookie
Image
JavaArray
JavaClass
JavaMethod
JavaObject
JavaPackage
Layer
MimeType
MimeTypeArray
Option
Url
Packages
Plugin
PluginArray
Popup
RangeError
ReferenceError
TypeError
StyleClass
StyleSelector
SyntaxError
TypeError
WScript
URIError
XMLHttpRequest
XMLSerializer
XPathEvaluator
XSLTDocument
XSLTProcessor
Attr
CDATASection
CharacterData
Comment
CSS2Properties
DOMException
DOMImplementation
DocumentType
Element
EntityReference
EvalError
NamedNodeMap
Node
NodeList
Notation
ProcessingInstruction
Text
HTMLElement
HTMLDocument
HTMLCollection
HTMLHtmlElement
HTMLHeadElement
HTMLLinkElement
HTMLTitleElement
HTMLMetaElement
HTMLBaseElement
HTMLIsIndexElement
HTMLStyleElement
HTMLBodyElement
HTMLFormElement
HTMLSelectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLInputElement
HTMLTextAreaElement
HTMLButtonElement
HTMLLabelElement
HTMLFieldSetElement
HTMLLegendElement
HTMLUListElement
HTMLOListElement
HTMLDListElement
HTMLDirectoryElement
HTMLMenuElement
HTMLLIElement
HTMLBlockquoteElement
HTMLDivElement
HTMLParagraphElement
HTMLHeadingElement
HTMLQuoteElement
HTMLPreElement
HTMLBRElement
HTMLBaseFontElement
HTMLFontElement
HTMLHRElement
HTMLModElement
HTMLAnchorElement
HTMLImageElement
HTMLObjectElement
HTMLParamElement
HTMLAppletElement
HTMLMapElement
HTMLAreaElement
HTMLScriptElement
HTMLTableElement
HTMLTableCaptionElement
HTMLTableColElement
HTMLTableSectionElement
HTMLTableRowElement
HTMLTableCellElement
HTMLFrameSetElement
HTMLFrameElement
HTMLIFrameElement
_newEnum
alert
atob
attachEvent
back
btoa
captureEvents
clearTimeout
clearInterval
close
CollectGarbage
confirm
createEventObject
createPopup
decodeURI
decodeURIComponent
detachEvent
dump
encodeURI
encodeURIComponent
escape
eval
execScript
find
forward
frameElement
getAttention
GetAttention
getClass
getComputedStyle
getResource
GetObject
home
isFinite
isNaN
moveBy
moveTo
open
openDialog
parseInt
parseFloat
prompt
releaseEvents
resizeBy
resizeTo
ScriptEngine
ScriptEngineMajorVersion
ScriptEngineMinorVersion
ScriptEngineBuildVersion
scroll
scrollBy
scrollByLines
scrollByPages
scrollIntoView
scrollTo
setCursor
setInterval
setTimeout
showHelp
showModalDialog
showModelessDialog
sizeToContent
stop
taint
toString
updateCommands
unescape
untaint
valueOf
_content
appCore
arguments
arity
callee
caller
clientInformation
clipboardData
closed
constructor
controllers
crypto
debug
defaultStatus
directories
document
element
event
external
history
forward
frames
Infinity
innerHeight
innerWidth
java
length
loading
location
locationbar
name
menubar
navigator
netscape
offscreenBuffering
opener
opera
outerHeight
outerWidth
pageXOffset
pageYOffset
parent
personalbar
pkcs11
prompter
prototype
returnValue
screen
screenLeft
screenTop
screenX
screenY
scrollX
scrollY
scrollbars
self
sidebar
status
statusbar
style
sun
title
toolbar
top
window
onafterprint
onbeforeprint
onbeforeunload
onblur
onchange
onclick
onclose
onerror
onfocus
onhelp
onload
onresize
onreset
onscroll
onselect
onunload
onmousedown
onmouseup
onmouseover
onmouseout
onkeydown
onkeyup
onkeypress
onmousemove
onsubmit
onreset
onchange
onselect
onclose
onabort
onerror
onpaint
ondragdrop
Soya
BOOTSTRAP
</resource>
<resource id="core.map">
abstract
break
continue
const
class
catch
case
debugger
default
double
delete
do
enum
extends
else
function
finally
float
false
for
get
instanceof
implements
import
int
in
if
long
null
new
protected
private
package
public
return
switch
static
super
set
typeof
throw
true
this
try
undefined
void
var
while
with
getter
setter
__defineGetter__
__defineSetter__
end
elif
cc_on
_win32
_win16
_mac
_alpha
_x86
_mc680x0
_PowerPC
_jscript
_jscript_build
_jscript_version
Array
Boolean
Date
Enumerator
Error
Function
Math
Number
Object
RegExp
String
VBArray
</resource>
<script language="JScript">
<![CDATA[
/*** <POD [ESCtool] (Soya/1.0.0-b10; crlvl:2/1; Tue, 28 Feb 2006 21:22:16 UTC)> ***/
/**
Proving that ESC actually can handle name-mangling and as a general self-sanity
check, ESC has been used to compress itself along with other required Soya-beans
while creating the package you see below. To examine these beans in a more human
readable form, get the latest distribution of the Soya API.
**/
function Soya_API($h)
{
this.name='Soya';
this.version='1.0.0-b10';
this.type='static';
this.debug=0;
this.host=$h;
this.libPath='/lib-soya/';
this.podPath='pods';
this.resourcePath='resources';
this.attachBean=$a;
this.declareBean=$b;
this.registerBean=$c;
this.BeanPrototype=Soya_BeanPrototype;
this.beans=new Object();
this.beans.all=new Array();
Soya_Loader.prototype=new this.BeanPrototype();
this.Loader=new Object();
this.Loader.orphans=new Array();
this.Loader.callbacks=new Object();
this.declareBean('Soya.BeanPrototype',null,this.name,false,true);
}
function Soya_VirtualBean(){}
function Soya_BeanPrototype(){
this.name='Soya.BeanPrototype';
}
function $a($i){
if(!$i.virtual){
eval($i.mutexName).prototype=$i;
eval($i.name+'='+(!$i.constructable?'new ':' ')+
$i.mutexName+(!$i.constructable?'()':''));
}
else eval($i.name+'=this.beans["'+$i.name+'"]');
$i.complete=true;
if(this.Loader&&this.Loader.callbacks[$i.name])
this.Loader.callbacks[$i.name](eval($i.name));
}
function $b($j,$k,$l,$m,$n){
var $o=$k?new this.BeanPrototype():new Soya_VirtualBean();
$o.name=$j;
$o.mutexName=$k||'Soya_VirtualBean';
$o.parentName=$l;
$o.iid=0;
$o.stack=new Array();
$o.complete=Boolean($n);
$o.constructable=($k&&!$m);
$o.virtual=!$k;
return(this.beans[$j]=this.beans.all[this.beans.all.length]=$o);
}
function $c($j,$m,$p,i){
var $q;
var $r=$j.split('\x2e');
var $k=$r.join('\x5f');
if(!this.beans[$j]){
if($p){
var $s='';
$q=$r[0];
for(i=1;i<$r.length-1;i++){
$s+=$q;
$q+=('\x2e'+$r[i]);
if(i<=$p&&!this.beans[$q])
this.attachBean(this.declareBean($q,null,$s,true,true));
}
}
$r.length-=$p?$p:1;
$q=$r.join('\x2e');
this.declareBean($j,$k,$q,$m);
if($r.length>1&&!this.beans[$q])
this.Loader.orphans[this.Loader.orphans.length]=this.beans[$j];
else{
this.attachBean(this.beans[$j]);
var $t=new Array();
for(i=0;i<this.Loader.orphans.length;i++)
if(this.Loader.orphans[i].parentName==$j)
this.attachBean(this.Loader.orphans[i]);
else $t[$t.length]=this.Loader.orphans[i];
this.Loader.orphans=$t;
}
}
return Boolean(i)
}
function $d($u){
this.getResourcePath=Function('sName',
"return(Soya.libPath + Soya.resourcePath + '/' + (sName||this.name).split('.').join('/') + '/')");
this.getClass=Function('sName','return eval(Soya.beans[sName || this.name].mutexName)');
this.toString=Function("return('[object ' + (this.name || 'noname') + ']')");
this.getBeanPath=Function('sName',
"return(Soya.libPath + (sName||this.name).split('.').join('/') + '.js')");
this.type='static';
if(!$u){
this.finalize=$f;
this.initialize=$e;
}
}
function $e($v){
this.iid=this.getClass().prototype.iid++;
if(this.stackable)
this.stack[this.iid]=this;
if(!Soya.beans[this.name].initialized){
$v=$v||
Soya.host[Soya.beans[this.name].mutexName+'_initialize'];
if(typeof($v)=='function')
Soya.beans[this.name].initialized=!$v(this.getClass(),this);
}
}
function $f($w){
$w=$w||
Soya.host[Soya.beans[this.name].mutexName+'_finalize'];
if(typeof($w)=='function')
$w(this.getClass(),this);
}
function Soya_Loader(){};
function $g($x,$y,$z){
if(!Soya.fso)
Soya.fso=new ActiveXObject('Scripting.FilesystemObject');
if(Soya.fso.FileExists($x)){
var $i=Soya.fso.GetFile($x),
$A=Soya.fso.OpenTextFile($i.Path),
$B=$A.Read($z||$i.Size);
$A.Close();
return $B;
}
else if(!$y)
return(WScript.Echo(this.name+' '+Soya.version+
'> File Not found: '+$x),WScript.Quit(99));
else return '';
}
Soya_BeanPrototype.prototype=new $d(0);
Soya_VirtualBean.prototype=new $d(1);
Soya_API.prototype=new $d(1);
var Soya=new Soya_API(this);
if(typeof(BOOTSTRAP)=='function')BOOTSTRAP(Soya);
function Soya_Common()
{
this.name='Soya.Common';
this.type='static';
this.version='1.03';
this.dependencies=[];
this.destroy=$E;
this.makeFunction=$G;
this.typematch=$F;
this.getObject=$C;
this.$ih=$H;
Function.prototype.getArguments=$D;
Soya.BeanPrototype.prototype.Extends=
Function('oBean','bOvr','Soya.Common.$ih(oBean, this, bOvr)');
Soya.BeanPrototype.prototype.Implements=
Function('oBean','bOvr','Soya.Common.$ih(this, oBean, bOvr)');
this.interfaces=new Object();
this.interfaces['Scripting.FilesystemObject']=Soya.fso;
}
function $C($I,$J){
if(typeof(this.interfaces[$I])=='undefined'){
if(typeof ActiveXObject=='function'){
Soya.host.msieax=null;
if(typeof Error=='function')
eval('try{Soya.host.msieax=new ActiveXObject("'+$I+'")}catch(e){}');
else{
var $K=String("on error resume next\nself.msieax=CreateObject('"+$I+"'))");
self.execScript($K,'vbscript');
}
if(!$J)
return Soya.host.msieax;
this.interfaces[$I]=Soya.host.msieax;
}
}
return this.interfaces[$I]||void(0);
}
function $D($L){
var $M=[],
$N=(isNaN($L)||$L<1)?
0:Math.min($L,this.arguments.length);
for(;$N<this.arguments.length;$N++)
$M[$M.length]=this.arguments[$N];
return $M;
}
function $E($O){
if($O!=null&&typeof($O)=='object')
for(var $P in $O){
if(typeof($O[$P])=='object'&&$O[$P])
if($O[$P].constructor&&!$O[$P].style){
this.destroy($O[$P]);
delete($O[$P]);
}
else $O[$P]=null;
}
}
function $F($Q,$R){
var $S;
switch(typeof($Q)){
case 'number':$S=2;break;
case 'boolean':$S=4;break;
case 'string':$S=8;break;
case 'function':$S=16;break;
case 'object':$S=32;break;
default:$S=1;break;
}
return Boolean($S&($R||62));
}
function $G($T){
if($T&&this.typematch($T,16))
return $T;
else return Function(($T&&this.typematch($T,8))?$T:'');
}
function $H($U,$V,$W){
for(var $P in $U)
if($P!='name'&&(!$W||typeof($V[$P])=='undefined'))
$V[$P]=$U[$P];
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.Common',true);
function Soya_WSH()
{
this.name='Soya.WSH';
this.type='static';
this.version='0.88';
this.dependencies=['Soya.Common','Soya.WSH.Registry'];
this.osInfo={};
this.arguments={length:0};
this.$09=function($00)
{return $00.length<2?$00:$00.replace(/^\\-/,'-').replace(/\\{2}/g,'\\')};
this.getArgument=function($01){return(this.arguments[$01]||"")}
this.getArguments=$X;
this.getOSInfo=$Z;
this.getShell=$Y;
}
function $X(){
if(!this.arguments.length&&WScript.Arguments.length){
var i,$02,$03=[],$04=new RegExp('^-+');
for(i=0;i<WScript.Arguments.length;i++)
$03[$03.length]=WScript.Arguments.item(i);
for(i=0;i<$03.length;i++){
$02=$03[i].replace($04,'-');
if($02.length>1&&$04.test($02)){
if(typeof $03[i+1]!='undefined'&&!$04.test($03[i+1]))
this.arguments[this.$09($02.replace($04,''))]=
this.$09($03[1+(i++)]);
else this.arguments[this.$09($02.replace($04,''))]=1;
};
else if($02.length)
this.arguments[this.arguments.length++]=this.$09($03[i]);
}
}
return this.arguments;
}
function $Y(){
if(!this.shell)
this.shell=Soya.Common.getObject('WScript.Shell');
return this.shell;
}
function $Z(){
if(this.osInfo.$0a)
return this.osInfo;
var $05=Soya.Common.getObject('Scripting.FilesystemObject'),
$06=this.getShell().ExpandEnvironmentStrings("%SYSTEMROOT%");
this.osInfo.MSIEVersion=Soya.WSH.Registry.regRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\Version');
this.osInfo.NETVersion=Soya.WSH.Registry.regRead('HKLM\SOFTWARE\Microsoft\.NETFramework\\Version')||-1;
this.osInfo.SPVersion=Soya.WSH.Registry.regRead('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CSDVersion')||-1;
this.osInfo.JSVersion=parseFloat(ScriptEngineMajorVersion()+'.'+ScriptEngineMinorVersion());
if($05.FolderExists($06+'\\system32'))
$07=$05.GetFileVersion($06+'\\system32\\kernel32.dll');
else if($05.FolderExists($06+'\\system'))
$07=$05.GetFileVersion($06+'\\system\\kernel32.dll');
if($07){
/^(\d)\.(\d+)\.(\d+)\.\d+$/.test($07);
this.osInfo.majorVersion=parseInt(RegExp.$1);
this.osInfo.minorVersion=parseInt(RegExp.$2,10);
this.osInfo.buildVersion=parseInt(RegExp.$3,10);
this.osInfo.version=$07;
var $08={
'4.00.950':'Win95',
'4.00.1111':'Win95 OSR2',
'4.00.1381':'WinNT',
'4.10.1998':'Win98',
'4.10.2222':'Win98SE',
'4.90.3000':'WinME',
'5.0.2195':'Win2K',
'5.10.2600':'WinXP'
};
this.osInfo.name=$08[$07.replace(/\.\d+$/,'')]||'unknown';
}
this.osInfo.$0a=1;
return this.osInfo;
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.WSH',true);
function Soya_Saltstorm_ESC($0t,$0u,$0v,$y)
{
this.name='Soya.Saltstorm.ESC';
this.version='1.14';
this.type='constructor';
this.dependencies=['Soya.Common','Soya.ECMA.Array'];
this.resourcePath=$0v||'';
this.crunchLevel=$0t||2;
this.substitute=false;
this.verbose=$0u;
this.silent=($y||typeof window=='object');
this.initialize();
this.flush();
}
function Soya_Saltstorm_ESC_initialize($0w,$0x){
$0y=$0x;
var $0z="(?:\"{2}|'{2}|\".*?.\"|'.*?.'|\\/(?!\\*|\\/)..*?\\/)";
var $0A="[-!%&;<=>~:\\/\\^\\+\\|\\,\\(\\)\\*\\?\\[\\]\\{\\}]+";
var $0B="\\/\\*(?!@).(?:.|\\n)*?\\*\\/|\\/\\/.*";
var $0C="\".*?.\"|'.*?.'|\\s*\\/{2,}.*\\n";
var $0D="\\}(?!catch|else|while)([^;,\\|\\.\\]\\)\\}])";
with($0w){
prototype.fileFilter=new RegExp('.+\\\\(?!$|_)\\w*\\.js$','i');
prototype.$1r=["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",9];
prototype.$1s={};
prototype.fso=Soya.Loader.fso||new ActiveXObject('Scripting.FilesystemObject');
prototype.core={};
prototype.bless={};
prototype.mangle={};
prototype.common={};
prototype.$1t=$g;
prototype.crunch=$0r;
prototype.flush=function(){this.buffer='';this.report=new $0c()};
prototype.getSubstitute=$0g;
prototype.loadMaps=$0d;
prototype.out=$0b;
prototype.load=$0e;
prototype.save=$0f;
prototype.getReport=$0s;
prototype.$1u=new RegExp("[$_]");
prototype.$1v=new RegExp("[^$\\w]","g");
prototype.$1w=new RegExp("^[\\x00\\.\"']");
prototype.$1x=new RegExp("\\s+$");
prototype.$1y=new RegExp("^\\s*\\W");
prototype.$1z=new RegExp("^[-\\\\+\"~'!]");
prototype.$1A=new RegExp("("+$0z+")|("+$0B+")","g");
prototype.$1B=new RegExp("("+$0C+")","g");
prototype.$1C=new RegExp("("+$0z+")|(\\r?\\n\\s+)|(\\x20{2,})","g");
prototype.$1D=new RegExp("("+$0z+")|(\\w+)?\\s+("+$0A+")","g");
prototype.$1E=new RegExp("("+$0z+")|("+$0A+")[ \\t]+","g");
prototype.$1F=new RegExp("("+$0z+")|function[\\n\\s]+([$\\w]+)","g");
prototype.$1G=new RegExp("("+$0z+")|("+$0B+")|(\\W[\\n\\s]*?[$\\w]+)\\b","gm");
prototype.$1H=new RegExp("("+$0z+")|(\\x00)|\\.[\\n\\s]*?([$_][$\\w]{3,})","g");
prototype.$1I=new RegExp("("+$0z+")|(\\S)\\s*[\\r\\n]+\\s*(\\S)","g");
prototype.$1J=new RegExp("[$\\w][$\\w]");
prototype.$1K=new RegExp("("+$0D+")","g");
}
}
function $0b($0E,$0F){
if(!this.silent){
var $0G=String((!$0F?'ESC> ':'')+($0E||''));
WScript.Echo($0G);
}
}
function $0c(){
this.scripts=[];
this.rawSize=
this.crunchedSize=
this.elapsedTime=0;
}
function $0d(){
if(this.$1L)
return;
var $0H,$0I,$0J,$0K,$0L;
for(var i=0;i<arguments.length;i++){
$0H=arguments[i].replace(/\W.+$/,'');
try{
$0J=getResource(arguments[i]).split(/\r?\n/g)||[];
for(var j=0;j<$0J.length;j++)
if($0J[j].length&&!$0y.$1y.test($0J[j]))
Soya_Saltstorm_ESC.prototype[$0H][$0J[j].replace($0y.$1x,'')]=1;
if(this.verbose)
this.out('Parsed map "'+$0H+'", '+$0J.length+' entries.')
}
catch($0M){
if($0M)
$0J=null;
}
if($0J)
continue;
else $0I=this.fso.BuildPath(this.resourcePath,arguments[i]);
if(/^common|core/.test(arguments[i])&&!this.fso.FileExists($0I)){
this.out('Couldn\'t $0N $0O:'+
this.fso.GetAbsolutePathName($0I));
return WScript.Quit(99);
}
else if(typeof this[$0H]!='object'){
this.out('Unrecognized mapname : '+$0H);
return WScript.Quit(99);
}
else if(this.fso.FileExists($0I)){
$0J=this.fso.OpenTextFile($0I);
$0L=0;
while(!$0J.AtEndOfStream){
$0K=$0J.ReadLine();
if($0K.length&&!$0y.$1y.test($0K))
Soya_Saltstorm_ESC.prototype[$0H][$0K.replace($0y.$1x,'')]=++$0L;
}
$0J.Close();
Soya_Saltstorm_ESC.prototype[$0H].length=$0L;
if(this.verbose)
this.out('Loaded map "'+$0H+'", '+$0L+' entries. ['+$0I+']');
}
}
this.$1L=1;
}
function $0e(){
var i,$0P,$0Q,$0R,$0S=[];
for(i=0;i<arguments.length;i++){
if(arguments[i]&&this.fso.FolderExists(arguments[i])){
$0R=new Enumerator(this.fso.GetFolder(arguments[i]).SubFolders);
for(;!$0R.atEnd();$0R.moveNext())
arguments[arguments.length++]=$0R.item().Path;
$0R=new Enumerator(this.fso.GetFolder(arguments[i]).Files);
for(;!$0R.atEnd();$0R.moveNext())
if($0R.item().Size&&this.fileFilter.test($0R.item().Path))
$0S.push($0R.item().Path);
}
else if(arguments[i])
$0S.push(arguments[i]);
}
for(i=0;i<$0S.length;i++){
if(!this.fso.FileExists($0S[i])){
this.out('Couldn\'t $0N $0T:"' + this.fso.GetAbsolutePathName(aLoadQueue[i]) + '"');
return WScript.Quit(99);
}
else if(this.verbose)
this.out('Loading script :"'+this.fso.GetAbsolutePathName($0S[i])+'"');
$0Q=this.fso.GetFile($0S[i]);
this.buffer+=(this.report.scripts.length?'\r\n':'');
this.buffer+=this.$1t($0Q.Path,true);
this.report.scripts.push(
$0Q.Path+' ('+($0Q.Size/1024).toFixed(2)+' kb)');
}
return $0S.length;
}
function $0f($0U,$0V){
var $0W;
if(!$0U){
this.out('Need an output filename!');
return WScript.Quit(99);
}
else if(this.fso.FolderExists($0U)){
this.out('Need an output filename, "'+
this.fso.GetAbsolutePathName($0U)+'" is a folder.');
return WScript.Quit(99);
}
this.outFile=this.fso.GetAbsolutePathName($0U);
this.outMode=$0V?'Writing':'Appending';
$0W=this.fso.OpenTextFile(this.outFile,($0V?2:8),true);
$0W.WriteLine(this.buffer);
$0W.Close();
}
function $0g($0X){
if(!this.$1s[$0X]){
var k=1;
while(k<5){
this.$1r[k]++;
if(this.$1r[k]&&!(this.$1r[k]%62)){
k++;
if(this.$1r.length==k)
this.$1r[k]=-1;
}
else break;
}
this.$1s[$0X]='$';
for(k=this.$1r.length-1;k>0;k--)
this.$1s[$0X]+=this.$1r[0].charAt(this.$1r[k]%62);
if(this.verbose)
this.out('Substituting ['+this.$1s[$0X]+'] -> ['+$0X+']');
}
return this.$1s[$0X];
}
function $0h($0Y,$0Z,$10){
if(typeof $10!='undefined')
return '';
else return $0Y;
}
function $0i($0Y,$11){
if(typeof $11!='undefined'&&/^\s+/.test($11))
return '\r\n';
else return $0Y;
}
function $0j($0Y,$12,$13){
if(typeof $12!='undefined')
return $0Y;
else if($13&&$13.length>2&&
($0y.mangle[$13]||$0y.$1u.test($13.charAt(0))))
$13=$0y.getSubstitute($13);
else Soya_Saltstorm_ESC.prototype.bless[$13]=1;
return String('function \x00'+$13);
}
function $0k($0Y,$12,$14,$15){
if(typeof $12=='undefined'&&typeof $14=='undefined'&&typeof $15=='string'){
$15=$15.replace(/\s+/g,'');
if(!$0y.$1w.test($15)&&isNaN(parseInt($15.substr(1),10))){
$15=$15.replace($0y.$1v,'');
if($15.length>2&&!$0y.core[$15]&&!$0y.common[$15]&&
!$0y.bless[$15]&&($0y.mangle[$15]||!$0y.mangle.length))
return $0Y.replace($15,$0y.getSubstitute($15));
}
}
return $0Y;
}
function $0l($0Y,$12,$16,$P){
if(typeof $P=='string')
return(!$0y.core[$P]&&!$0y.common[$P]&&!$0y.bless[$P])?
String('.'+$0y.getSubstitute($P)):$0Y;
else if(typeof $12!='undefined')
return $0Y;
else return '';
}
function $0m($0Y,$12,$17,$18,$19){
if(typeof $12!='undefined')
return $0Y;
else if(typeof $17!='undefined')
return '\r\n';
else if(typeof $18!='undefined')
return ' ';
else return '';
}
function $0n($0Y,$12,$1a,$1b){
if(typeof $12=='undefined'){
if(!$0y.$1z.test($1b)||!$1a||!$0y.core[$1a])
return($1a||'')+$1b;
else return $0Y;
}
else return $12;
}
function $0o($0Y,$12,$1b){
if(typeof $12!='undefined')
return $0Y;
else return $1b;
}
function $0p($0Y,$1c,$1d){
return('};'+$1d);
}
function $0q($0Y,$12,$1e,$1f){
if(typeof $1e=='undefined')
return $0Y;
var $1g=($0y.$1J.test($1e+$1f))?' ':'';
return $1e+$1g+$1f;
}
function $0r($1h,$0t,$1i){
var $B=(typeof $1h=='string')?$1h:this.buffer;
this.loadMaps('core.map','common.map','bless.map','mangle.map');
if(!this.buffer.length&&!$1h)
return String();
else if(typeof $0t=='number')
this.crunchLevel=$0t;
var $1j=(new Date()).getTime()-1;
var $1k=$B.length;
this.report.rawSize+=$B.length;
if(this.crunchLevel>=1){
$B=$B.replace(this.$1A,$0h)
.replace(this.$1B,$0i)
.replace(/\s*\r?\n/g,'\r\n');
if(this.verbose)
this.out('Removing comments, empty lines and trailing whitespace, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.crunchLevel>=2){
$B=$B.replace(this.$1C,$0m);
if(this.verbose)
this.out('Removing tabs and spaces, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
$B=$B.replace(this.$1D,$0n);
if(this.verbose)
this.out('Removing spaces left to operators, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
$B=$B.replace(this.$1E,$0o);
if(this.verbose)
this.out('Removing spaces right to operators, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.substitute||$1i||this.crunchLevel>=4){
$B=$B.replace(this.$1F,$0j);
$B=$B.replace(this.$1G,$0k);
$B=$B.replace(this.$1H,$0l);
if(this.verbose)
this.out('Substitution summary, saved '+
($1k-$B.length)+' bytes.');
$1k=$B.length;
}
if(this.crunchLevel>=3){
$B=$B.replace(this.$1I,$0q);
$B=$B.replace(this.$1K,$0p);
$B+='\r\n';
if(this.verbose){
this.out('Removing newlines, saved '+
($1k-$B.length)+' bytes.');
this.out('',1);
}
}
if(typeof $1h=='string'){
this.report.crunchedSize+=$B.length;
this.buffer+=$B;
}
else{
this.buffer=$B;
this.report.crunchedSize=$B.length;
}
this.report.elapsedTime+=(new Date()).getTime()-$1j;
return this.buffer;
}
function $0s($1l){
var $1m=($1l||'\r\n'),
$1n=this.label?String($1m+this.label+$1m):'';
if(!this.report.elapsedTime){
$1n+='Nothing to report, yet...';
return(!$1o)?this.out($1n,1):$1n;
}
var $1p=Boolean(this.substitute||this.crunchLevel>=4),
$1q=this.report.rawSize-this.report.crunchedSize;
if(this.report.scripts.length){
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" Crunching script(s):\r\n\t * "+this.report.scripts.join("\r\n\t * ")+$1m;
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" "+(this.outMode||"Put")+" to : "+(this.outFile||"[buffer]")+" ("+
(this.report.crunchedSize/1024).toFixed(2)+" kb)"+$1m;
}
$1n+="-----------------------------------------------------------------------------"+$1m;
$1n+=" Processtime :\t"+(this.report.elapsedTime/1000).toFixed(3)+" secs"+$1m;
$1n+=" Crunch-level :\t"+this.crunchLevel+$1m;
$1n+=" Subst. engine :\t"+($1p?'On':'Off')+$1m;
if($1p)
$1n+=" Substitutions :\t"+(this.$1r[1]-9)+$1m;
$1n+=" Original size :\t"+(this.report.rawSize/1024).toFixed(2)+" kb"+$1m;
$1n+=" Crunched size :\t"+(this.report.crunchedSize/1024).toFixed(2)+" kb"+$1m;
$1n+=" Saving ratio :\t"+($1q/1024).toFixed(2)+" kb"+$1m;
$1n+=" -'' ''- (%) :\t"+(($1q/this.report.rawSize)*100).toFixed(2)+" %"+$1m;
$1n+="-----------------------------------------------------------------------------"+$1m;
return $1n;
}
if(typeof(Soya)=='object')Soya.registerBean('Soya.Saltstorm.ESC',false,1);
/*** </POD> ***/
]]>
</script>
<script language="JScript">
<![CDATA[
/*
Command flow control script for ESC.wsf
Edited : 2005-02-06
*/
var oShell = WScript.CreateObject('WScript.Shell');
if(!oShell)
WScript.Quit(64);
// Do we have Jscript 5.5+ ?
else if(oShell && parseFloat(ScriptEngineMajorVersion() + '.' + ScriptEngineMinorVersion()) < 5.5)
oShell.Popup(getResource('jscript'), 64, WScript.ScriptName, 16), WScript.Quit(4);
// Is ESC executed under cscript ?
// if not let user select switching to cscript automagically.
else if(oShell && WScript.FullName.toLowerCase().indexOf('cscript') < 0){
if(oShell.Popup(getResource('wscript'), 64, WScript.ScriptName, 52) == 6)
oShell.Run('%comspec% /Q /K cscript //NoLogo ' + WScript.ScriptName + ' -a', 9);
WScript.Quit(3);
}
// get the cmdline arguments formatted in a nice manner.
var oArgs = Soya.WSH.getArguments();
// should we run in verbose-mode ?;
var bVerbose = Boolean(!oArgs.s && !oArgs.silent && (oArgs.v || oArgs.verbose));
// create an instance of the ESC object.
var esc = new Soya.Saltstorm.ESC(oArgs.l || oArgs.level, bVerbose);
esc.label = 'ESC (ECMAScript Cruncher) ' + esc.version +
'\r\nCopyright (C) 2001-2005 Thomas Loo <tloo@saltstorm.net>';
esc.resourcePath = esc.fso.GetParentFolderName(WScript.ScriptFullName || '.');
var sOutput = String(oArgs.oa || oArgs.ow || '');
if(oArgs.a || oArgs.about){
WScript.Echo(getResource('about'));
WScript.Quit(1);
}
else if(oArgs.c || oArgs.copyright){
WScript.Echo('\n' + esc.label + getResource('copyright'));
WScript.Quit(1);
}
else if(oArgs.e || oArgs.example){
WScript.Echo('\n' + esc.label + getResource('example'));
WScript.Quit(1);
}
// if there are options missing, print out the help table and quit.
else if((oArgs.h || oArgs.help) || !sOutput.length || !oArgs[0]){
WScript.Echo('\n' + esc.label + getResource('usage'));
WScript.Quit((oArgs.h || oArgs.help) ? 1 : 2);
}
// Wake up the variable substitution engine if option set (-$);
esc.substitute = Boolean(oArgs.$);
// load input files;
for(var i = 0; i < oArgs.length; i++)
esc.load(oArgs[i]);
// crunch baby, crunch!;
if(sOutput.toUpperCase() == 'STDOUT'){
esc.silent = true;
WScript.StdOut.Write(esc.crunch());
}
else if(sOutput.length){
esc.crunch();
esc.save(sOutput, Boolean(oArgs.ow));
// write report to stdout if not silence'd.
if(!oArgs.s && !oArgs.silent)
WScript.StdOut.Write(esc.getReport());
}
// Shutting down nicely..
WScript.Quit(0);
]]>
</script>
</job>
</package>