File: makeWebBuildModuleList.js

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (108 lines) | stat: -rw-r--r-- 3,158 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//This file generates a list of modules that can be used in a web build.
//This file should be called from ant/command line, and the output file
//needs to be generated before the web build will work.


function buildTreeData(/*Object*/obj, /*String*/nodeName){
	// summary:
	//		makes a TreeV3-friendly data structure.
	
	var result = null;
	var childNames = [];
	if(obj["dojoModuleName"]){
		result = { title: nodeName, dojoModuleName: obj["dojoModuleName"]};
	}else{
		result = {};
	}
	
	//Working with a branch.
	for(var childName in obj){
		if(childName != "dojoModuleName"){
			childNames.push(childName);
		}
	}
	childNames = childNames.sort();
	if(childNames.length > 0){
		result.children = [];
		result = { title: nodeName, children: []};
		for(var i = 0; i < childNames.length; i++){
			result.children.push(buildTreeData(obj[childNames[i]], childNames[i]));
		}
	}
	return result;
}


//START of the "main" part of the script.
//This is the entry point for this script file.
var srcRoot = arguments[0];
var outputFileName = arguments[1];

//Load Dojo so we can reuse code.
djConfig={
	baseUrl: "../../../dojo/"
};
load('../../../dojo/dojo.js');

load("../jslib/logger.js");
load("../jslib/fileUtil.js");

//Get a list of files that might be modules.
var fileList = fileUtil.getFilteredFileList(srcRoot, /\.js$/, true);

var provideRegExp = /dojo\.provide\(\".*\"\)/g;

//Search the modules for a matching dojo.provide() call.
//Need to do this because some files (like nls/*.js files) are
//not really modules.
var provideList = [];
for(var i = 0; i < fileList.length; i++){
	var fileName = fileList[i];
	var fileContents = new fileUtil.readFile(fileName);

	var matches = fileContents.match(provideRegExp);
	
	if(matches){
		for(var j = 0; j < matches.length; j++){
			//strip off the .js file extension
			var modFileName = fileName.substring(0, fileName.length - 3);
			var provideName = matches[j].substring(matches[j].indexOf('"') + 1, matches[j].lastIndexOf('"'));

			//Skip certain kinds of modules not needed in end use.
			if(provideName.indexOf("tests.") != -1
				|| provideName.indexOf("._") != -1
				|| provideName.indexOf(".robot") != -1){
				continue;
			}

			//Only allow the provides that match the file name.
			//So, the different dijit permutations of dijit.form.Button will not show up.
			if (modFileName.lastIndexOf(provideName.replace(/\./g, "/")) == modFileName.length - provideName.length){
				provideList.push(provideName);
				break;
			}
		}
	
	}
}

provideList = provideList.sort();

logger.trace(provideList);

//Create the object that represents the module structures.
/*var moduleHolder = {};

for(var i = 0; i < provideList.length; i++){
	var moduleObject = dojo.getObject(provideList[i], moduleHolder, true);
	moduleObject.obj[moduleObject.prop] = {dojoModuleName: provideList[i] };
}

//Transform the object into something appropriate for a tree control.
var treeData = buildTreeData(moduleHolder, "Dojo Modules");

//Output the results.
fileUtil.saveFile(outputFileName, "var treeData = " + dojo.toJson(treeData) + ";");
*/
fileUtil.saveFile(outputFileName, "var provideList = [" + provideList + "];");