1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/*
DynAPI Compiler Beta 1
Written 2002 by Raymond Irving
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
var jsCLevel='high';
var jsCExclude='';
var jsCLastFile = '';
var jsCLastFileName = '';
var jsCDebug=false; //@IF:DEBUG directive
var jsCNS4=true; //@IF:NS4 directive
var jsFileIndex = -1;
var jsCLastUnCompressedSize = 0;
var jsCLastCompressedSize = 0;
// Compiles or Compresses the select dynapi source folder
// When check==true compressor will check dynapi files in source folder for missing semi-colons
function compress(check) {
var f=document.frmcompress;
var source=f.txtsource.value;
var target=f.txttarget.value;
jsFileIndex = -1;
jsCCheck = check;
jsCLevel = (jsCCheck)? 'low':f.cbolevel.value;
jsCDebug = f.chkdebug.checked;
jsCNS4 = f.chkns4.checked;
jsCLastUnCompressedSize = 0;
jsCLastCompressedSize = 0;
// build exclude list
jsCExclude='';
if(f.chkcvs.checked) jsCExclude='CVS';
for(var i=0;i<f.chk.length;i++){
if(!f.chk[i].checked){
jsCExclude+=((jsCExclude)? ',':'')+f.chk[i].value;
}
}
// check for valid source and target path
if(!CheckFolder(source)) {
alert('Invalid Source Path "'+source+'"');
return;
}else if(!CheckFolder(target)) {
alert('Invalid Destination Path "'+target+'"');
return;
}
// store javascript files in an array and copy non-javascript files into target
BuildFileSturcure(source,target,jsCExclude);
document.images['bar'].style.width='0%';
document.images['bar'].style.visibility='visible';
f.txtstatus.value='Compiling....';
f.txtsizestatus.value='';
document.images['bar'].style.width="1%";
CompressNextFile();
showScreen(jsCCheck);
};
// CompressNextFile: Compresses one file at a time using the crunch() function (compressor.js)
function CompressNextFile(state,strText){
var f=document.frmcompress;
var i,a,p,srcFile,tarFile,content;
var totalFiles;
if(state=='status'){
// Display status from Crunch() functions
f.txtstatus.value='Compiling ['+jsCLastFileName+'] - '+strText;
}
else{
if (jsCCheck && state=="complete"){
// Check file for semi-colon errors
// a much better error checking system is needed here
var t='',l,exclude='{},;';
var ar = strText.split('\n');
for(var i=0;i<ar.length;i++){
l=strTrim(ar[i]);
if (l && l.length){
ok=false;
ch=l.substr(l.length-1,1);
if(ar[i]!='}' && exclude.indexOf(ch)>=0) ok=true
if(!ok){
l=l.replace(/</g,'<');
l=l.replace(/>/g,'>');
t+=' Line: '+(i+1)+': '+l+'<br>'
+' File: '+jsCLastFile+'<br><br>';
}
}
}
if(t){
var dv=document.all['dvscreen'];
dv.innerHTML=dv.innerHTML+t+"<hr>";
}
}
if(state=="complete"){
// Save compressed data
if(jsCLevel!='none' && (jsCLastFileName+'').toLowerCase()=='dynapi.js') {
strText='// The DynAPI Distribution is distributed under the terms of the GNU LGPL license.\n'
+strText;
}
jsCLastCompressedSize+=strText.length;
SaveFile(jsCLastFile,strText);
f.txtsizestatus.value=' Last size in bytes: Before = '+jsCLastUnCompressedSize+' / After = '+jsCLastCompressedSize+' / '
+' Diff = '+(jsCLastUnCompressedSize-jsCLastCompressedSize);
}
// Move to next file
jsFileIndex+=1;
totalFiles=GetTotalFiles();
if(jsFileIndex<=totalFiles){
// get target and source file
srcFile=GetSRCFile(jsFileIndex);
tarFile=jsCLastFile=GetTARFile(jsFileIndex);
// update status
p=((jsFileIndex+1)/(totalFiles+1))*100;
a=jsCLastFile.split('\\');
jsCLastFileName=a[a.length-1];
f.txtstatus.value='Compiling ['+jsCLastFileName+']....';
document.images['bar'].style.width=p+"%";
// get file content
content=OpenFile(srcFile)+'';
jsCLastUnCompressedSize+=content.length;
if(content.indexOf('\n')<0) content=content.split("\r"); // MAC
else content=content.split("\n"); // PC, UNIX
content=content.join('<$Link/>');
if(!jsCDebug){
// Remove Debug conditional code blocks
content = RemoveCondition('DEBUG',content);
content=content.replace(/dynapi\.debug\.print\(/g,'dPrint\(');
}
if(!jsCNS4) {
// Remove NS4 conditinal code blocks
content = RemoveCondition('NS4',content);
}
content=content.replace(/\<\$Link\/\>/g,'\n');
// Compress the file content
Crunch(content,jsCLevel,CompressNextFile);
}
else {
// finished compressing js files
f.txtstatus.value="Ready";
document.images['bar'].style.visibility='hidden';
}
}
};
// jsCheckFileState: Used by fsobject to check if the file should be copied or compressed
function jsCheckFileState(f,pth){
var state=0,ignore=false;
var a,copy=2, compress=1;
f=f+''; a=f.split(".");
// check if file is a part of the debug library
ignore=(!jsCDebug && f.indexOf('debug')==0)
// check if file is a part of the NS4 library
ignore=(ignore || (!jsCNS4 && f.indexOf('ns4')==0))
if(!ignore){
// if .js file the compress otherwise copy the file
if(a[a.length-1]=="js") state=compress;
else state=copy;
}
return state;
};
// Remove conditional statements
function RemoveCondition(tag,content) {
var lines = content.split('//]:'+tag);
var t = [''];
// loop through conditional staments
for (i=0;i<lines.length;i++) {
if(lines[i].indexOf('//@IF:'+tag+'[')<0) t[t.length] = lines[i];
else{
if(tag=='NS4') t[t.length] = lines[i].replace(/\/\/\@IF:NS4\[(.*)$/g,'');
else if(tag=='DEBUG') t[t.length] = lines[i].replace(/\/\/\@IF:DEBUG\[(.*)$/g,'');
}
}
return t.join('');
}
// Misc functions
function showScreen(b){
var dv=document.all['dvscreen'];
dv.innerHTML='';
dv=document.all['dvscreenrow'];
if(b) dv.style.display='block';
else dv.style.display='none';
}
function showHideAbout() {
var dv=document.all['dvabout'];
if(dv.style.display=='block') dv.style.display='none';
else dv.style.display='block';
}
function strTrim(s,dir){
if(!s) return;
else s+=''; // make sure s is a string
dir=(dir)? dir:'<>';
if(dir=='<'||dir=='<>') s=s.replace(/^(\s+)/g,'');
if(dir=='>'||dir=='<>') s=s.replace(/(\s+)$/g,'');
return s;
};
|