* @prop cleanup {Boolean} (optional) clean up temp files after done -
* Defaults to false if you set tmpDir, otherwise true.
*/
- cleanup : true, //
-
+ cleanup : true,
+ /**
+ * @prop prefix {String} (optional) prefix of directory to be stripped of when
+ * Calculating md5 of filename
+ */
+ prefix : '',
out : '', // if no target is specified - then this will contain the result
packAll : function() // do the packing (run from constructor)
// at this point we can write a language file...
if (this.translateJSON) {
- this.writeTranslateFile(fn, minfile, tr.translateMap);
+
+ this.writeTranslateFile(fn, minfile, toks);
}
this.activeFile = fn;
*
*/
- writeTranslateFile : function(fn, minfile, map)
+ writeTranslateFile : function(fn, minfile, toks)
{
+
+ var map = {};
+ var _this = this;
+ toks.forEach(function (t) {
+ if (t.type == 'STRN' && t.name == 'DOUBLE_QUOTE') {
+ var sval = t.data.substring(1,t.data.length-1);
+ var ffn = fn.substring(_this.prefix.length);
+ map.push( sval);
+ }
+ })
+
var transfile = minfile + '.lang.trans';
var transmd5 = minfile + '.lang';
+ print("writeTranslateFile " + transfile);
var i = 0;
var v = '';
if (File.exists(transfile)) {
if (!i ) {
return; // no strings in file...
}
- var ff = fn.split('/');
- var ffn = ff[ff.length-1];
+ var ffn = fn.substring(this.prefix.length);
- File.write(transfile, "\n" + ffn.toSource() + " : {");
+ File.write(transfile, "\n'" + ffn + "' : {");
var l = '';
var _tout = {}
{
//print("STRING HANDLER");
// callback when outputing compressed file,
- var data = tok.outData !== false ? tok.outData : tok.data;
+ var data = tok.data;
if (!this.translateJSON) {
// print("TURNED OFF");
return data;
}
- if (tok.name == SINGLE_QUOTE) {
+ if (tok.name == 'SINGLE_QUOTE') {
return data;
}
// return tok.outData;
// }
+ var sval = tok.data.substring(1,data.length-1);
+ var fn = this.activeFile.substring(this.prefix.length);
-
- var ff = this.activeFile.split('/');
- var ffn = ff[ff.length-1];
- return '_T["' + this.md5(ffn + '-' + sval) + '"]';
+ return '_T["' + this.md5(fn + '-' + sval) + '"]';
}
if (!token) { // can return false at EOF!
break;
}
- if (token.name == "VAR") { // kludge..
+ if (token.name == "VAR" || token.data == ',') { // kludge..
continue;
}
//this.logR("parseScope GOT VAR : <B>" + token.toString() + "</B>");
if (token.type !="NAME") {
- print(token.toString());
+ for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
+ print(this.ts.tokens[i].toString());
+ }
+
print( "var without ident");
Seed.quit()
}
* -t Translate json file.
* -w Cache / working dir.
* -C no cleanup (use with -w if you need are using a cache directory.)
+ * -p prefix for translation md5 generator (directory that files are in, and is removed
+ * from path when generating an md5 for the translated name.
*
* compresses files listed as arguments and outputs result
*/
i++;
continue;
}
-
+ if (args[i] == '-p') {
+ cfg.prefix = args[i+1];
+ i++;
+ continue;
+ }
if (args[i] == '-C') {
cfg.cleanup = false;
continue;
}
+ if (cfg.files.indexOf(args[i]) > -1) {
+ continue; // remove dupes.
+ }
cfg.files.push(args[i]);
}
var pack;
pack = new Packer(cfg)
} catch (e) {
print("ERROR " + e.toString());
- Seed.quit();
+ throw e;
}
if (!pack.target) {
print(pack.out);