source: Dev/branches/rest-dojo-ui/client/util/buildscripts/cldr/wrap.js @ 273

Last change on this file since 273 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.0 KB
Line 
1/**
2 * Takes plain JSON structures and wraps them as to requireJS i18n bundles
3 */
4
5djConfig={baseUrl: "../../../dojo/"};
6
7load("../../../dojo/dojo.js");
8load("../jslib/logger.js");
9load("../jslib/fileUtil.js");
10load("cldrUtil.js");
11
12dojo.require("dojo.i18n");
13
14var dir/*String*/ = arguments[0];// ${dojo}/dojo/cldr/nls
15var logDir = arguments[1];
16var logStr = "";
17
18print('wrap.js...');
19
20var 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
26var 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       
32fileLists.forEach(function(fileList){
33        var map = {},
34            list = [],
35            rootFile;
36        fileList.forEach(function(file /*Java String*/){
37logStr += "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;
45logStr += "rootFile="+file.toString()+"\n";
46
47                }else{
48logStr += "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
55logStr += "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
73fileUtil.saveUtf8File(logDir + '/wrap.log',logStr+'\n');
74//print('wrap finished, please refer to logs at ' + logDir + ' for more details.');
Note: See TracBrowser for help on using the repository browser.