| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
djConfig={baseUrl: "../../../dojo/", paths: {"dojo/_base/xhr": "../util/buildscripts/cldr/xhr"}}; |
| 6 |
|
| 7 |
load("../../../dojo/dojo.js"); |
| 8 |
load("../jslib/logger.js"); |
| 9 |
load("../jslib/fileUtil.js"); |
| 10 |
load("cldrUtil.js"); |
| 11 |
|
| 12 |
dojo.require("dojo.i18n"); |
| 13 |
|
| 14 |
var dir = arguments[0]; |
| 15 |
var logDir = arguments[1]; |
| 16 |
var logStr = ""; |
| 17 |
|
| 18 |
print('wrap.js...'); |
| 19 |
|
| 20 |
var wrap = function(contents){ |
| 21 |
return "\n//begin v1.x content\n" + contents + "\n//end v1.x content\n"; |
| 22 |
}; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
var fileLists = fileUtil.getFilteredFileList(dir, /\.js$/, true, false, true) |
| 27 |
.map(function(file){ |
| 28 |
var name = file.substring(file.lastIndexOf("/")); |
| 29 |
return fileUtil.getFilteredFileList(dir, new RegExp(name+"$"), true); |
| 30 |
}); |
| 31 |
|
| 32 |
fileLists.forEach(function(fileList){ |
| 33 |
var map = {}, |
| 34 |
list = [], |
| 35 |
rootFile; |
| 36 |
fileList.forEach(function(file ){ |
| 37 |
logStr += "WRAP processing file: "+file.toString()+"\n"; |
| 38 |
var path = file.split("/"), |
| 39 |
locale = path[path.length-2], |
| 40 |
obj = dojo.fromJson(fileUtil.readFile(file)); |
| 41 |
|
| 42 |
if(locale=="nls"){ |
| 43 |
rootFile = file; |
| 44 |
map.root = obj; |
| 45 |
logStr += "rootFile="+file.toString()+"\n"; |
| 46 |
|
| 47 |
}else{ |
| 48 |
logStr += "locale added: "+locale+"\n"; |
| 49 |
list.push(locale); |
| 50 |
map[locale] = true; |
| 51 |
fileUtil.saveUtf8File(file, "define(" + wrap(dojo.toJson(obj, true)) + ");"); |
| 52 |
} |
| 53 |
}); |
| 54 |
|
| 55 |
logStr += "writing rootFile="+rootFile+"\n"; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
var contents = "{ root:\n"; |
| 60 |
contents += wrap(dojo.toJson(map.root, true)); |
| 61 |
if(list.length){ |
| 62 |
list.sort(); |
| 63 |
list.forEach(function(l){ |
| 64 |
contents += ',\n\t"' + l + '": true'; |
| 65 |
}); |
| 66 |
contents += "\n"; |
| 67 |
} |
| 68 |
contents += "}"; |
| 69 |
|
| 70 |
fileUtil.saveUtf8File(rootFile, "define(" + contents + ");"); |
| 71 |
}); |
| 72 |
|
| 73 |
fileUtil.saveUtf8File(logDir + '/wrap.log',logStr+'\n'); |
| 74 |
|