1 | define([ |
---|
2 | "build/argv", |
---|
3 | "build/fs", |
---|
4 | "build/buildControl", |
---|
5 | "build/messages", |
---|
6 | "build/process", |
---|
7 | "dojox/json/ref" |
---|
8 | ], function(argv, fs, bc, messages, process, json){ |
---|
9 | var parseViews = function(mids, mainLayer, views, params){ |
---|
10 | for(var key in views){ |
---|
11 | // ignore naming starting with _ (jsonref adding is own stuff in there) |
---|
12 | if(key.indexOf("_") == 0){ |
---|
13 | continue; |
---|
14 | } |
---|
15 | var view = views[key]; |
---|
16 | // TODO deal with "./" shortcut & default view location (which relies on "./") |
---|
17 | if(view.controller && view.controller != "none"){ |
---|
18 | var mid = view.controller.replace(/(\.js)$/, ""); |
---|
19 | if(!bc.layers[mid] && bc.multipleAppConfigLayers){ |
---|
20 | bc.layers[mid] = { include: [], exclude: [ "dojo/dojo", mainLayer ] }; |
---|
21 | mids = bc.layers[mid].include; |
---|
22 | } |
---|
23 | mids.push(mid); |
---|
24 | } |
---|
25 | if(view.template){ |
---|
26 | // we need dojo/text to load templates, let's put it in the main layer in all cases |
---|
27 | // as this will be shared by a lot of views |
---|
28 | if(!params.text){ |
---|
29 | params.text = true; |
---|
30 | bc.layers[mainLayer].include.push("dojo/text"); |
---|
31 | } |
---|
32 | mids.push(view.template); |
---|
33 | } |
---|
34 | if(view.nls){ |
---|
35 | // we use nls let's add dojo/i18n to the main layer as it will be shared by a lot of views |
---|
36 | if(!params.nls){ |
---|
37 | params.nls = true; |
---|
38 | bc.layers[mainLayer].include.push("dojo/i18n"); |
---|
39 | } |
---|
40 | mids.push(view.nls); |
---|
41 | } |
---|
42 | if(view.dependencies){ |
---|
43 | Array.prototype.splice.apply(mids, [ mids.length, 0 ].concat(view.dependencies)); |
---|
44 | } |
---|
45 | if(view.views){ |
---|
46 | parseViews(mids, mainLayer, view.views, params); |
---|
47 | } |
---|
48 | } |
---|
49 | }; |
---|
50 | return function(){ |
---|
51 | var config; |
---|
52 | try{ |
---|
53 | config = json.fromJson(fs.readFileSync(bc.getSrcModuleInfo(argv.args.appConfigFile, null, false).url)); |
---|
54 | }catch(e){ |
---|
55 | console.log(e); |
---|
56 | } |
---|
57 | if(config){ |
---|
58 | var mids = [], params = {}; |
---|
59 | if(config.loaderConfig){ |
---|
60 | require(config.loaderConfig); |
---|
61 | } |
---|
62 | // main layer |
---|
63 | var mainLayer; |
---|
64 | if(!argv.args.appConfigLayer){ |
---|
65 | // no layer specified, take the first one |
---|
66 | for(var l in bc.layers){ |
---|
67 | mainLayer = l; |
---|
68 | break; |
---|
69 | } |
---|
70 | }else{ |
---|
71 | mainLayer = argv.args.appConfigLayer; |
---|
72 | if(!bc.layers[mainLayer]){ |
---|
73 | bc.layers[mainLayer] = { include: [], exclude: [ "dojo/dojo"] }; |
---|
74 | } |
---|
75 | } |
---|
76 | if(config.dependencies){ |
---|
77 | mids = mids.concat(config.dependencies); |
---|
78 | } |
---|
79 | if(config.controllers){ |
---|
80 | mids = mids.concat(config.controllers); |
---|
81 | } |
---|
82 | if(config.modules){ |
---|
83 | mids = mids.concat(config.modules); |
---|
84 | } |
---|
85 | if(config.transit){ |
---|
86 | mids.push(config.transit); |
---|
87 | }else{ |
---|
88 | mids.push("dojox/css3/transit"); |
---|
89 | } |
---|
90 | if(config.template){ |
---|
91 | params.text = true; |
---|
92 | bc.layers[mainLayer].include.push("dojo/text"); |
---|
93 | mids.push(config.template); |
---|
94 | } |
---|
95 | if(config.controller && config.controller != "none"){ |
---|
96 | mids.push(config.controller.replace(/(\.js)$/, "")); |
---|
97 | } |
---|
98 | if(config.nls){ |
---|
99 | // we use nls let's add dojo/i18n to the main layer as it will be shared by a lot of views |
---|
100 | params.nls = true; |
---|
101 | bc.layers[mainLayer].include.push("dojo/i18n"); |
---|
102 | mids.push(config.nls); |
---|
103 | } |
---|
104 | if(config.view){ |
---|
105 | // we use a custom view class |
---|
106 | mids.push(config.view); |
---|
107 | }else{ |
---|
108 | // regular view |
---|
109 | mids.push("dojox/app/View"); |
---|
110 | } |
---|
111 | // go into the view children |
---|
112 | if(config.views){ |
---|
113 | parseViews(mids, mainLayer, config.views, params); |
---|
114 | } |
---|
115 | Array.prototype.splice.apply(bc.layers[mainLayer].include, [bc.layers[mainLayer].length, 0].concat(mids)); |
---|
116 | }else{ |
---|
117 | messages.log("pacify", argv.args.appConfigFile+" is not a valid dojox/app JSON config file"); |
---|
118 | process.exit(-1); |
---|
119 | } |
---|
120 | }; |
---|
121 | }); |
---|
122 | |
---|