Debian Codegraph @

util/buildscripts/cldr/wrap.js

raw symbols SCIP
1 /**
2 * Takes plain JSON structures and wraps them as to requireJS i18n bundles
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/*String*/ = arguments[0];// ${dojo}/dojo/cldr/nls
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 // for each .js file in the top-level directory, make a filtered list
25 // of all files matching that name in the directory tree
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 /*Java String*/){
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 // var contents = wrap(dojo.toJson(map, true));
57
58 // Assemble file contents to include 1.x markers around map.root
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 //print('wrap finished, please refer to logs at ' + logDir + ' for more details.');