source: Dev/branches/rest-dojo-ui/client/util/buildscripts/makeDojoJsWeb.js @ 256

Last change on this file since 256 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: 3.4 KB
Line 
1//START of the "main" part of the script.
2//This is the entry point for this script file.
3load("buildUtil.js");
4load("buildUtilXd.js");
5
6var result = "ERROR";
7
8var buildDirectory = new String(arguments[0]);
9var depList = new String(arguments[1]);
10var provideList = new String(arguments[2]);
11var version = new String(arguments[3]);
12var xdDojoUrl = new String(arguments[4]);
13
14depList = depList.split(",");
15
16//Check if there were no provideList (the caller can send string "null"
17//to indicate that the command line parameter is empty. We need some string
18//to make sure all the arguments are in the right spot.
19if(provideList == "null"){
20        provideList = "[]";
21}else{
22        provideList = provideList.split(",");
23        provideList = '["' + provideList.join('","') + '"]';
24}
25
26var dependencyResult;
27eval('dependencyResult = {depList: ["' + depList.join('","') + '"], provideList: ' + provideList + '};');
28
29//Make sure we are dealing with JS files and that the paths are not outside
30//of the working area. Do this to discourage fetching arbitrary files from
31//the server.
32var deps = dependencyResult.depList;
33var isInputOk = true;
34for(var i = 0; i < deps.length; i++){
35        var matches = deps[i].match(/\.\./g);
36        if((matches && matches.length > 1) || !deps[i].match(/\.js$/) || deps[i].indexOf(0) == '/'){
37                print("Error: Invalid file set.");
38                isInputOk = false;
39                break;
40        }
41}
42
43if(isInputOk){
44        //Load dojo (needed for string interning)
45        djConfig={
46                baseRelativePath: "../"
47        };
48        load('../dojo.js');
49        dojo.require("dojo.string.extras");
50        dojo.require("dojo.crypto.MD5");
51
52        var buildSigDir = dojo.crypto.MD5.compute(depList.sort().join(","), dojo.crypto.outputTypes.Hex);
53        try{
54                //xxx createLayerContents is broken: need kwargs? it is optional but probably should provide it.
55                var contents = buildUtil.createLayerContents(dependencyResult.depList, dependencyResult.provideList, version);
56                var compressedContents = "";
57                var prefixes = [["dojo", "src"]];
58       
59                //Make sure any dojo.requireLocalization calls are modified
60                //so that they inform the loader of valid locales that can be loaded.
61                contents = buildUtil.modifyRequireLocalization(contents, prefixes);
62
63                //Intern strings.
64                contents = buildUtil.interningRegexpMagic("xdomain", contents, djConfig.baseRelativePath, prefixes, [], true);
65               
66                //Set the xdomain dojo url
67                if(xdDojoUrl){
68                        contents = buildUtilXd.setXdDojoConfig(contents, xdDojoUrl);
69                }
70
71                //Compress code.
72                compressedContents = buildUtil.optimizeJs("dojo.js", contents, "", "shrinksafe");
73
74                //Add copyright
75                var copyright = fileUtil.readFile("copyright.txt");
76                var buildNotice = fileUtil.readFile("build_notice.txt");
77                contents = copyright + buildNotice + contents;
78                compressedContents = copyright + buildNotice + compressedContents;
79               
80                //Prep cache location
81                var buildCachePath = buildDirectory + "/" + buildSigDir + "/";
82
83                //Create needed directories for cache location.
84                var dirFile = new java.io.File(buildCachePath + "compressed");
85                var dirsOk = dirFile.mkdirs();
86
87                result = "dirFile: " + dirFile.getAbsolutePath() + ", dirsOK: " + dirsOk;
88               
89                //Create build contents file
90                var buildContents = dependencyResult.provideList.sort().join("\n");
91
92                //Save files to disk
93                fileUtil.saveUtf8File(buildCachePath + "dojo.js", contents);
94                fileUtil.saveUtf8File(buildCachePath + "compressed/dojo.js", compressedContents);
95                fileUtil.saveUtf8File(buildCachePath + "build.txt", buildContents);
96               
97                result = "OK";
98        }catch(e){
99                result = "ERROR: " + e;
100        }
101
102        print(result);
103}
Note: See TracBrowser for help on using the repository browser.