File: makeDojoJsWeb.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 (103 lines) | stat: -rw-r--r-- 3,488 bytes parent folder | download | duplicates (7)
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
//START of the "main" part of the script.
//This is the entry point for this script file.
load("buildUtil.js");
load("buildUtilXd.js");

var result = "ERROR";

var buildDirectory = new String(arguments[0]);
var depList = new String(arguments[1]);
var provideList = new String(arguments[2]);
var version = new String(arguments[3]);
var xdDojoUrl = new String(arguments[4]);

depList = depList.split(",");

//Check if there were no provideList (the caller can send string "null"
//to indicate that the command line parameter is empty. We need some string
//to make sure all the arguments are in the right spot.
if(provideList == "null"){
	provideList = "[]";
}else{
	provideList = provideList.split(",");
	provideList = '["' + provideList.join('","') + '"]';
}

var dependencyResult;
eval('dependencyResult = {depList: ["' + depList.join('","') + '"], provideList: ' + provideList + '};');

//Make sure we are dealing with JS files and that the paths are not outside
//of the working area. Do this to discourage fetching arbitrary files from
//the server.
var deps = dependencyResult.depList;
var isInputOk = true;
for(var i = 0; i < deps.length; i++){
	var matches = deps[i].match(/\.\./g);
	if((matches && matches.length > 1) || !deps[i].match(/\.js$/) || deps[i].indexOf(0) == '/'){
		print("Error: Invalid file set.");
		isInputOk = false;
		break;
	}
}

if(isInputOk){
	//Load dojo (needed for string interning)
	djConfig={
		baseRelativePath: "../"
	};
	load('../dojo.js');
	dojo.require("dojo.string.extras");
	dojo.require("dojo.crypto.MD5");

	var buildSigDir = dojo.crypto.MD5.compute(depList.sort().join(","), dojo.crypto.outputTypes.Hex);
	try{
		//xxx createLayerContents is broken: need kwargs? it is optional but probably should provide it.
		var contents = buildUtil.createLayerContents(dependencyResult.depList, dependencyResult.provideList, version);
		var compressedContents = "";
		var prefixes = [["dojo", "src"]];
	
		//Make sure any dojo.requireLocalization calls are modified
		//so that they inform the loader of valid locales that can be loaded.
		contents = buildUtil.modifyRequireLocalization(contents, prefixes);

		//Intern strings.
		contents = buildUtil.interningRegexpMagic("xdomain", contents, djConfig.baseRelativePath, prefixes, [], true);
		
		//Set the xdomain dojo url
		if(xdDojoUrl){
			contents = buildUtilXd.setXdDojoConfig(contents, xdDojoUrl);
		}

		//Compress code.
		compressedContents = buildUtil.optimizeJs("dojo.js", contents, "", "shrinksafe");

		//Add copyright
		var copyright = fileUtil.readFile("copyright.txt");
		var buildNotice = fileUtil.readFile("build_notice.txt");
		contents = copyright + buildNotice + contents;
		compressedContents = copyright + buildNotice + compressedContents;
		
		//Prep cache location
		var buildCachePath = buildDirectory + "/" + buildSigDir + "/";

		//Create needed directories for cache location.
		var dirFile = new java.io.File(buildCachePath + "compressed");
		var dirsOk = dirFile.mkdirs();

		result = "dirFile: " + dirFile.getAbsolutePath() + ", dirsOK: " + dirsOk;
		
		//Create build contents file
		var buildContents = dependencyResult.provideList.sort().join("\n");

		//Save files to disk
		fileUtil.saveUtf8File(buildCachePath + "dojo.js", contents);
		fileUtil.saveUtf8File(buildCachePath + "compressed/dojo.js", compressedContents);
		fileUtil.saveUtf8File(buildCachePath + "build.txt", buildContents);
		
		result = "OK";
	}catch(e){
		result = "ERROR: " + e;
	}

	print(result);
}