* @class Packer
* Create a new packer
*
+ * Use with pack.js
+ *
+ *
* Usage:
* <code>
*
Packer = imports['JSDOC/Packer.js'].Packer;
-var x = new Packer(
- [ "/location/of/file1.js", "/location/of/file2.js", ... ],
- "/location/of"
+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',
+ translateJson : '', // json based list of strings in all files.
+
// set to false to stop translation happening..
/**
*
*/
- 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..