Debian Codegraph @

util/buildscripts/webbuild/makeWebBuildModuleList.js

raw symbols SCIP
1 //This file generates a list of modules that can be used in a web build.
2 //This file should be called from ant/command line, and the output file
3 //needs to be generated before the web build will work.
4
5
6 function buildTreeData(/*Object*/obj, /*String*/nodeName){
7 // summary:
8 // makes a TreeV3-friendly data structure.
9
10 var result = null;
11 var childNames = [];
12 if(obj["dojoModuleName"]){
13 result = { title: nodeName, dojoModuleName: obj["dojoModuleName"]};
14 }else{
15 result = {};
16 }
17
18 //Working with a branch.
19 for(var childName in obj){
20 if(childName != "dojoModuleName"){
21 childNames.push(childName);
22 }
23 }
24 childNames = childNames.sort();
25 if(childNames.length > 0){
26 result.children = [];
27 result = { title: nodeName, children: []};
28 for(var i = 0; i < childNames.length; i++){
29 result.children.push(buildTreeData(obj[childNames[i]], childNames[i]));
30 }
31 }
32 return result;
33 }
34
35
36 //START of the "main" part of the script.
37 //This is the entry point for this script file.
38 var srcRoot = arguments[0];
39 var outputFileName = arguments[1];
40
41 //Load Dojo so we can reuse code.
42 djConfig={
43 baseUrl: "../../../dojo/"
44 };
45 load('../../../dojo/dojo.js');
46
47 load("../jslib/logger.js");
48 load("../jslib/fileUtil.js");
49
50 //Get a list of files that might be modules.
51 var fileList = fileUtil.getFilteredFileList(srcRoot, /\.js$/, true);
52
53 var provideRegExp = /dojo\.provide\(\".*\"\)/g;
54
55 //Search the modules for a matching dojo.provide() call.
56 //Need to do this because some files (like nls/*.js files) are
57 //not really modules.
58 var provideList = [];
59 for(var i = 0; i < fileList.length; i++){
60 var fileName = fileList[i];
61 var fileContents = new fileUtil.readFile(fileName);
62
63 var matches = fileContents.match(provideRegExp);
64
65 if(matches){
66 for(var j = 0; j < matches.length; j++){
67 //strip off the .js file extension
68 var modFileName = fileName.substring(0, fileName.length - 3);
69 var provideName = matches[j].substring(matches[j].indexOf('"') + 1, matches[j].lastIndexOf('"'));
70
71 //Skip certain kinds of modules not needed in end use.
72 if(provideName.indexOf("tests.") != -1
73 || provideName.indexOf("._") != -1
74 || provideName.indexOf(".robot") != -1){
75 continue;
76 }
77
78 //Only allow the provides that match the file name.
79 //So, the different dijit permutations of dijit.form.Button will not show up.
80 if (modFileName.lastIndexOf(provideName.replace(/\./g, "/")) == modFileName.length - provideName.length){
81 provideList.push(provideName);
82 break;
83 }
84 }
85
86 }
87 }
88
89 provideList = provideList.sort();
90
91 logger.trace(provideList);
92
93 //Create the object that represents the module structures.
94 /*var moduleHolder = {};
95
96 for(var i = 0; i < provideList.length; i++){
97 var moduleObject = dojo.getObject(provideList[i], moduleHolder, true);
98 moduleObject.obj[moduleObject.prop] = {dojoModuleName: provideList[i] };
99 }
100
101 //Transform the object into something appropriate for a tree control.
102 var treeData = buildTreeData(moduleHolder, "Dojo Modules");
103
104 //Output the results.
105 fileUtil.saveFile(outputFileName, "var treeData = " + dojo.toJson(treeData) + ";");
106 */
107 fileUtil.saveFile(outputFileName, "var provideList = [" + provideList + "];");
108