// <script type="text/javascript">
-XObject = imports.XObject.XObject;
-File = imports.File.File;
+XObject = imports.XObject.XObject;
+File = imports.File.File;
-TokenReader = imports['JSDOC/TokenReader.js'].TokenReader;
+TokenReader = imports['JSDOC/TokenReader.js'].TokenReader;
+ScopeParser = imports['JSDOC/ScopeParser.js'].ScopeParser;
+TokenStream = imports['JSDOC/TokenStream.js'].TokenStream;
+CompressWhite = imports['JSDOC/CompressWhite.js'].CompressWhite;
+
+GLib = imports.gi.GLib;
/**
- * @class JSDOC.Packer
+ * @namespace JSDOC
+ * @class Packer
* Create a new packer
*
+ * Use with pack.js
+ *
+ *
* Usage:
* <code>
*
-var x = new JSDOC.Packer(
- [ "/location/of/file1.js", "/location/of/file2.js", ... ],
- "/location/of"
+Packer = imports['JSDOC/Packer.js'].Packer;
+var x = new Packer({
+
+ files : [ "/location/of/file1.js", "/location/of/file2.js", ... ],
+ target : "/tmp/output.js",
+ debugTarget : "/tmp/output.debug.js", // merged file without compression.
+ translateJson : "/tmp/translate.json",
+
+
);
x.packFiles(
"/location/of/temp_batch_dir",
* directly before an eval statement, it will compress all the code around the eval,
* and not rename the variables 'avarname'
*
- * Dont try running this on a merged uncompressed large file - it's horrifically slow.
+ * Dont try running this on a merged uncompressed large file - it's used to be horrifically slow. not sure about now..
* Best to use lot's of small classes, and use it to merge, as it will cache the compaction
*
*
*
- * @param {Array} files List of Files - MUST BE WITH ABSOLUTE PATH eg. [ '/usr/src/xyz/abc.js', .... ]
- * @param {String} source_path top level directory of source (used to work out the relative names for the minimized temp files)
+ * Notes for translation
+ * - translation relies on you using double quotes for strings if they need translating
+ * - single quoted strings are ignored.
+ *
+ * Generation of indexFiles
+ * - translateIndex = the indexfile
+ *
+ *
+ *
+ *
+
*/
-Packer = function(files, spath)
+Packer = function(cfg)
{
- this.files = files;
- this.spath = spath; // source path
- this.aliasList = { }; // list of maps Roo.asdfasdfasf => Roo.A1
+
+ XObject.extend(this, cfg);
+ if (!this.files) {
+ throw "No Files";
+ }
+ if (!this.target) {
+ throw "No Target";
+ }
+
this.timer = new Date() * 1;
- this.translate = true;
+
}
Packer.prototype = {
+ /**
+ * @prop files {Array} list of files to compress (must be full path)
+ */
+ files : false,
+ /**
+ * @prop target {String} target to write files to - must be full path.
+ */
+ target : '',
+ /**
+ * @prop debugTarget {String} target to write files debug version to (uncompacted)- must be full path.
+ */
+ debugTarget : '', // merged file without compression.
- bpath : '',
+ workingDir : '/tmp',
- // set to false to stop translation happening..
+ translateJson : '', // json based list of strings in all files.
+
+ tmpFile : false, // list of temporary files - cleaned up at end..
/**
* Pack the files.
*
*/
- packFiles : function(bpath, allfile, debugfile) {
- var str;
- var spath = this.spath;
- var files = this.files;
- this.bpath = bpath;
- // old var names - fixme..
- var dout = debugfile;
- //File.write(dout, "");
+ packFiles : function() {
- var outpath = allfile;
-
- var transfile = bpath + '/_translation_.js';
//this.transOrigFile= bpath + '/../lang.en.js'; // needs better naming...
//File.write(this.transfile, "");
- File.write(dout, "");
- File.write(allfile, "");
- for(var i=0; i < files.length; i++) {
+ File.write(this.target, "");
+ if (this.debugTarget) {
+ File.write(this.debugTarget, "");
+ }
+
+ for(var i=0; i < this.files.length; i++) {
+ var file = this.files[i];
- print("reading " +files[i] );
- if (!File.exists(files[i])) {
- print("SKIP (does not exist) " + files[i]);
+ print("reading " +file );
+ if (!File.exists(file)) {
+ print("SKIP (does not exist) " + file);
continue;
}
-
- File.append(dout, File.read(files[i]));
+ if (this.debugTarget) {
+ File.append(this.debugTarget, File.read(files[i]));
+ }
// it's a good idea to check with 0 compression to see if the code can parse!!
// debug file..
this.timerPrint("Tokenized");
//return;//
- var sp = new JSDOC.ScopeParser(new JSDOC.TokenStream(toks, str.length));
+ var sp = new ScopeParser(new TokenStream(toks, str.length));
this.timerPrint("Converted to Parser");
sp.packer = this;
sp.buildSymbolTree();
var l = '';
var _tout = {}
- File.write(transmd5, '');
+ File.write(transmd5, '');
for(v in map) {
File.append(transfile, l + "\n\t \"" + v + '" : "' + v + '"');
l = ',';
// strings are raw... - as the where encoded to start with!!!
- File.append(transmd5, '_T[' + (ffn + '-' + v).md5().toSource() + ']="'+v+"\";\n");
+ File.append(transmd5, '_T["' + this.md5(ffn + '-' + v) + '"]="'+v+"\";\n");
}
File.append(transfile, "\n},"); // always one trailing..
+ },
+ md5 : function (string)
+ {
+
+ return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5, string, string.length);
+
},
stringHandler : function(tok)
{
var ff = this.activeFile.split('/');
var ffn = ff[ff.length-1];
- return '_T[' + (ffn + '-' + sval).md5().toSource() + ']';
+ return '_T["' + this.md5(ffn + '-' + sval) + '"]';
}
-});
+};