* @cfg {String} target to write files to - must be full path.
*/
string target;
+ FileOutputStream targetStream = null;
/**
* @cfg {String} debugTarget target to write files debug version to (uncompacted)- must be full path.
*/
string targetDebug;
-
+
+
+ FileOutputStream targetDebugStream = null;
/**
* @cfg {String} tmpDir (optional) where to put the temporary files.
* if you set this, then files will not be cleaned up
this.files.add(f); //?? easier way?
}
}
- FileOutputStream targetStream = null;
- FileOutputStream targetDebugStream = null;
+
public void pack()
{
string file_contents;
// debug Target
- if (this.debugTargetStream !=null) {
+ if (this.targetDebugStream !=null) {
FileUtils.get_contents(file,out file_contents);
- this.debugTarget.write(file_contents);
+ this.targetDebugStream.write(file_contents);
loaded_string = false;
}
// it's a good idea to check with 0 compression to see if the code can parse!!
// if we are translating, write the translations strings at the top
// of the file..
-
+ /*
if (this.translateJSON) {
}
}
-
+ */
print("MERGING SOURCE");
for(var i=0; i < this.files.length; i++) {
var file = this.files[i];
- var minfile = this.tmpDir + '/' + file.replace(/\//g, '.');
+ var minfile = this.tmpDir + '/' + file.replace('/', '.');
if (!File.exists(minfile)) {
var str = File.read(minfile);
print("using MIN FILE "+ minfile);
if (str.length) {
- if (this.target) {
- File.append(this.target, '//' + file + "\n");
- File.append(this.target, str + "\n");
+ if (this.targetStream != null) {
+ this.targetStream.write("//" + file + "\n");
+ this.targetStream.write(str + "\n");
+
} else {
- this.out += '//' + file + "\n";
+ this.out += "//" + file + "\n";
this.out += str + "\n";
}
}
if (this.cleanup) {
- File.remove(minfile);
+ FileUtils.remove(minfile);
}
}
- },
+ }
/**
* Core packing routine for a file
*
},
+
- timerPrint: function (str) {
- var ntime = new Date() * 1;
- var tdif = ntime -this.timer;
- this.timer = ntime;
- print('['+tdif+']'+str);
- },
-
- /**
- *
- * Translation concept...
- * -> replace text strings with _T....
- * -> this file will need inserting at the start of the application....
- * -> we need to generate 2 files,
- * -> a reference used to do the translation, and the _T file..
- *
- *
- * We store the trsum on the token...
- *
- */
-
- writeTranslateFile : function(fn, minfile, toks)
- {
-
- var map = {}; // 'string=> md5sum'
- var _this = this;
- var t, last, next;
-
-
- var tokfind = function (j,dir) {
- while (1) {
- if ((dir < 0) && (j < 0)) {
- return false;
- }
- if ((dir > 0) && (j >= toks.length)) {
- return false;
- }
- j += dir;
- if (toks[j].type != 'WHIT') {
- return toks[j];
- }
- }
- return false;
-
- }
-
-
- for (var i=0;i<toks.length;i++) {
-
- t = toks[i];
- if (t.type != 'STRN') {
- continue;
- }
- if (t.name != 'DOUBLE_QUOTE') {
- continue;
- }
-
- last = tokfind(i,-1);
- next = tokfind(i,+1);
-
- // we have to ignore key values on objects
-
- // defined by
- // last == '{' or ',' and
- // next == ':'
-
- if (next &&
- next.type == 'PUNC' &&
- next.data == ':' &&
- last &&
- last.type == 'PUNC' &&
- (last.data == ',' || last.data == '{')
- ){
- continue; // found object key... - we can not translate these
- }
-
- var sval = t.data.substring(1,t.data.length-1);
- var ffn = fn.substring(_this.prefix.length);
-
- t.trsum = _this.md5(ffn + '-' + sval);
- map[sval] = t.trsum;
-
-
-
- }
-
-
- var transfile = minfile + '.lang.trans';
- var transmd5 = minfile + '.lang';
- print("writeTranslateFile " + transfile);
- var i = 0;
- var v = '';
- if (File.exists(transfile)) {
- File.remove(transfile);
- }
- if (File.exists(transmd5)) {
- File.remove(transmd5);
- }
- for(v in map) { i++; break };
- if (!i ) {
- return; // no strings in file...
- }
- var ffn = fn.substring(this.prefix.length);
-
-
- File.write(transfile, "\n'" + ffn + "' : {");
- var l = '';
- var _tout = {}
-
- File.write(transmd5, '');
- for(v in map) {
- if (!v.length) {
- continue;
- }
- File.append(transfile, l + "\n\t\"" + v + "\" : \"" + v +"\"");
- l = ',';
- // strings are raw... - as the where encoded to start with!!!
- // so we should not need to encode them again.. - just wrap with "
- 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)
- {
- //print("STRING HANDLER");
- // callback when outputing compressed file,
- var data = tok.data;
- if (!this.translateJSON) {
- // print("TURNED OFF");
- return data;
- }
- if (tok.name == 'SINGLE_QUOTE') {
- return data;
- }
-
- if (typeof(tok.trsum) == 'undefined') {
- return data;
- }
-
- return '_T["' + tok.trsum + '"]';
-
- var sval = data.substring(1,data.length-1);
- // we do not clean up... quoting here!??!!?!?!?!?
-
-
- // blank with tabs or spaces..
- //if (!sval.replace(new RegExp("(\\\\n|\\\\t| )+",'g'), '').length) {
- // return tok.outData;
- // }
-
- var sval = tok.data.substring(1,data.length-1);
- var fn = this.activeFile.substring(this.prefix.length);
-
-
- return '_T["' + this.md5(fn + '-' + sval) + '"]';
-
-
- }
+
+ //stringHandler : function(tok) -- not used...
};