1 | define([ |
---|
2 | "require", |
---|
3 | "./argv", |
---|
4 | "./fs", |
---|
5 | "./fileUtils", |
---|
6 | "./buildControlDefault", |
---|
7 | "./v1xProfiles", |
---|
8 | "./stringify", |
---|
9 | "./process", |
---|
10 | "./messages", |
---|
11 | "dojo/text!./help.txt" |
---|
12 | ], function(require, argv, fs, fileUtils, bc, v1xProfiles, stringify, process, messages, helpText) { |
---|
13 | // |
---|
14 | // Process the arguments given on the command line to build up a profile object that is used to instruct and control |
---|
15 | // the build process. |
---|
16 | // |
---|
17 | // This modules is a bit tedious. Is methodically goes through each option set, cleaning and conditioning user input making it |
---|
18 | // easy to use for the remainder of the program. Readers are advised to tackle it top-to-bottom. There is no magic...just |
---|
19 | // a whole bunch of imperative programming. |
---|
20 | // |
---|
21 | |
---|
22 | if(!isNaN(argv)){ |
---|
23 | // if argv is a number, then it's an exit code |
---|
24 | bc.exitCode = argv; |
---|
25 | return bc; |
---|
26 | } |
---|
27 | |
---|
28 | eval(require.scopeify("./fs, ./fileUtils, ./v1xProfiles")); |
---|
29 | var |
---|
30 | isString= function(it) { |
---|
31 | return typeof it === "string"; |
---|
32 | }, |
---|
33 | |
---|
34 | isNonemptyString= function(it){ |
---|
35 | return isString(it) && it.length; |
---|
36 | }, |
---|
37 | |
---|
38 | isDefined= function(it){ |
---|
39 | return typeof it !="undefined"; |
---|
40 | }, |
---|
41 | |
---|
42 | cleanupFilenamePair= function(item, srcBasePath, destBasePath, hint) { |
---|
43 | var result; |
---|
44 | if (isString(item)) { |
---|
45 | result= [computePath(item, srcBasePath), computePath(item, destBasePath)]; |
---|
46 | } else { |
---|
47 | result= [computePath(item[0], srcBasePath), computePath(item[1], destBasePath)].concat(item.slice(2)); |
---|
48 | } |
---|
49 | if (!isAbsolutePath(result[0]) || !isAbsolutePath(result[1])) { |
---|
50 | bc.log("inputInvalidPath", ["path", item, "hint", hint]); |
---|
51 | } |
---|
52 | return result; |
---|
53 | }, |
---|
54 | |
---|
55 | slashTerminate= function(path){ |
---|
56 | return path + /\/$/.test(path) ? "" : "/"; |
---|
57 | }, |
---|
58 | |
---|
59 | isEmpty= function(it) { |
---|
60 | for (var p in it) return false; |
---|
61 | return true; |
---|
62 | }, |
---|
63 | |
---|
64 | mix= function(dest, src) { |
---|
65 | dest= dest || {}; |
---|
66 | src= src || {}; |
---|
67 | for (var p in src) dest[p]= src[p]; |
---|
68 | return dest; |
---|
69 | }, |
---|
70 | |
---|
71 | mixPackage= function(packageInfo) { |
---|
72 | var name= packageInfo.name; |
---|
73 | bc.packageMap[name]= mix(bc.packageMap[name], packageInfo); |
---|
74 | }, |
---|
75 | |
---|
76 | // mix a profile object into the global profile object |
---|
77 | mixProfileObject= function(src) { |
---|
78 | // the profile properties... |
---|
79 | // paths, plugins, transforms, staticHasFeatures |
---|
80 | // ...are mixed one level deep; messageCategories, messages, packages, and packagePaths require special handling; all others are over-written |
---|
81 | // FIXME: the only way to modify the transformJobs vector is to create a whole new vector? |
---|
82 | for (var p in src) { |
---|
83 | if (!/paths|plugins|messages|transforms|staticHasFeatures|packages|packagePaths|defaultConfig/.test(p)) { |
---|
84 | bc[p]= src[p]; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | // the one-level-deep mixers |
---|
89 | ["paths","plugins","transforms","staticHasFeatures"].forEach(function(p) { |
---|
90 | bc[p]= mix(bc[p], src[p]); |
---|
91 | }); |
---|
92 | |
---|
93 | // messages require special handling |
---|
94 | if(src.messageCategories){ |
---|
95 | for(p in src.messageCategories){ |
---|
96 | bc.addCategory(p, src.messageCategories[p]); |
---|
97 | } |
---|
98 | } |
---|
99 | (src.messages || []).forEach(function(item){bc.addMessage.apply(bc, item);}); |
---|
100 | |
---|
101 | |
---|
102 | // packagePaths and packages require special processing to get their contents into packageMap; do that first... |
---|
103 | // process packagePaths before packages before packageMap since packagePaths is less specific than |
---|
104 | // packages is less specific than packageMap. Notice that attempts to edit an already-existing package |
---|
105 | // only edits specific package properties given (see mixPackage, above) |
---|
106 | for (var base in src.packagePaths) { |
---|
107 | src.packagePaths[base].forEach(function(packageInfo) { |
---|
108 | if (isString(packageInfo)) { |
---|
109 | packageInfo= {name:packageInfo}; |
---|
110 | } |
---|
111 | packageInfo.location= catPath(base, packageInfo.name); |
---|
112 | mixPackage(packageInfo); |
---|
113 | }); |
---|
114 | }; |
---|
115 | (src.packages || []).forEach(function(packageInfo) { |
---|
116 | if (isString(packageInfo)) { |
---|
117 | packageInfo= {name:packageInfo}; |
---|
118 | } |
---|
119 | mixPackage(packageInfo); |
---|
120 | }); |
---|
121 | |
---|
122 | // defaultConfig requires special handling |
---|
123 | for(p in src.defaultConfig){ |
---|
124 | if(p=="hasCache"){ |
---|
125 | mix(bc.defaultConfig.hasCache, src.defaultConfig.hasCache); |
---|
126 | }else{ |
---|
127 | bc.defaultConfig[p]= src.defaultConfig[p]; |
---|
128 | } |
---|
129 | } |
---|
130 | }; |
---|
131 | |
---|
132 | argv.args.profiles.forEach(function(item) { |
---|
133 | var temp= mix({}, item), |
---|
134 | build= item.build; |
---|
135 | delete temp.build; |
---|
136 | mixProfileObject(temp); |
---|
137 | build && mixProfileObject(build); |
---|
138 | }); |
---|
139 | |
---|
140 | // lastly, explicit command line switches override any evaluated profile objects |
---|
141 | for (var argName in argv.args) if (argName!="profiles") { |
---|
142 | bc[argName]= argv.args[argName]; |
---|
143 | } |
---|
144 | |
---|
145 | // at this point the raw profile object has been fully initialized; clean it up and look for errors... |
---|
146 | bc.basePath= computePath(bc.basePath, process.cwd()); |
---|
147 | var releaseDir = catPath(bc.releaseDir || "../release", bc.releaseName || ""); |
---|
148 | bc.destBasePath= computePath(releaseDir, bc.basePath); |
---|
149 | |
---|
150 | // compute global copyright, if any |
---|
151 | bc.copyright = isNonemptyString(bc.copyright) ? (maybeRead(computePath(bc.copyright, bc.basePath)) || bc.copyright) : ""; |
---|
152 | bc.copyrightLayers = !!bc.copyrightLayers; |
---|
153 | bc.copyrightNonlayers = !!bc.copyrightNonlayers; |
---|
154 | |
---|
155 | // compute files, dirs, and trees |
---|
156 | (function () { |
---|
157 | for (var property in {files:1, dirs:1, trees:1}) { |
---|
158 | if(bc[property] instanceof Array){ |
---|
159 | bc[property]= bc[property].map(function(item) { |
---|
160 | return cleanupFilenamePair(item, bc.basePath, bc.destBasePath, property); |
---|
161 | }); |
---|
162 | } |
---|
163 | } |
---|
164 | })(); |
---|
165 | |
---|
166 | // cleanup the replacements (if any) |
---|
167 | (function() { |
---|
168 | var cleanSet= {}, src, dest; |
---|
169 | for (src in bc.replacements) { |
---|
170 | cleanSet[computePath(src, bc.basePath)]= bc.replacements[src]; |
---|
171 | } |
---|
172 | bc.replacements= cleanSet; |
---|
173 | })(); |
---|
174 | |
---|
175 | // explicit mini and/or copyTests wins; explicit copyTests ignores explicit mini |
---|
176 | if(!("mini" in bc)){ |
---|
177 | bc.mini = true; |
---|
178 | } |
---|
179 | if(!("copyTests" in bc)){ |
---|
180 | bc.copyTests = !bc.mini; |
---|
181 | } |
---|
182 | if(isString(bc.copyTests)){ |
---|
183 | bc.copyTests = bc.copyTests.toLowerCase(); |
---|
184 | } |
---|
185 | if(bc.copyTests!="build"){ |
---|
186 | // convert to pure boolean |
---|
187 | bc.copyTests = !!bc.copyTests; |
---|
188 | } |
---|
189 | |
---|
190 | // clean up bc.packageMap and bc.paths so they can be used just as in dojo loader/bdLoad |
---|
191 | (function() { |
---|
192 | // so far, we've been using bc.packageMap to accumulate package info as it is provided by packagePaths and/or packages |
---|
193 | // in zero to many profile scripts. This routine moves each package config into bc.packages which is a map |
---|
194 | // from package name to package config (this is different from the array the user uses to pass package config info). Along |
---|
195 | // the way, each package config object is cleaned up and all default values are calculated. Finally, the |
---|
196 | // global packageMap (a map from package name to package name) is computed. |
---|
197 | |
---|
198 | function processPackage(pack){ |
---|
199 | var packName = pack.name, |
---|
200 | basePath = pack.basePath || bc.basePath; |
---|
201 | if(!pack.packageJson){ |
---|
202 | pack.packageJson = argv.readPackageJson(catPath(computePath(pack.location || ("./" + packName), basePath), "package.json"), "missingPackageJson"); |
---|
203 | } |
---|
204 | var packageJson = pack.packageJson; |
---|
205 | if(packageJson){ |
---|
206 | if(packageJson.version){ |
---|
207 | bc.log("packageVersion", ["package", packName, "version", packageJson.version]); |
---|
208 | |
---|
209 | // new for 1.7, if version is not provided, the version of the dojo package is used |
---|
210 | if(typeof bc.version=="undefined" && packName=="dojo"){ |
---|
211 | bc.version = packageJson.version; |
---|
212 | } |
---|
213 | } |
---|
214 | if(packageJson.main && !pack.main){ |
---|
215 | pack.main= packageJson.main; |
---|
216 | } |
---|
217 | if(packageJson.directories && packageJson.directories.lib && !pack.location){ |
---|
218 | pack.location = catPath(getFilepath(packageJson.selfFilename), packageJson.directories.lib); |
---|
219 | } |
---|
220 | if("dojoBuild" in packageJson){ |
---|
221 | var defaultProfile = argv.readProfile("profile", catPath(getFilepath(packageJson.selfFilename), packageJson.dojoBuild)); |
---|
222 | for (var p in defaultProfile) { |
---|
223 | if (!(p in pack)) { |
---|
224 | pack[p]= defaultProfile[p]; |
---|
225 | }else if(p in {resourceTags:1}){ |
---|
226 | // these are mixed one level deep |
---|
227 | // TODO: review all profile properties and see if there are any others than resourceTags that ought to go here |
---|
228 | mix(pack[p], defaultProfile[p]); |
---|
229 | } |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | // build up info to tell all about a package; all properties semantically identical to definitions used by dojo loader/bdLoad |
---|
235 | pack.main= isString(pack.main) ? pack.main : "main"; |
---|
236 | if(pack.main.indexOf("./")==0){ |
---|
237 | pack.main = pack.main.substring(2); |
---|
238 | } |
---|
239 | if(pack.destMain && pack.destMain.indexOf("./")==0){ |
---|
240 | pack.destMain = pack.destMain.substring(2); |
---|
241 | } |
---|
242 | |
---|
243 | pack.location= computePath(pack.location || ("./" + packName), basePath); |
---|
244 | pack.packageMap= pack.packageMap || 0; |
---|
245 | require.computeMapProg(pack.packageMap, (pack.mapProg= [])); |
---|
246 | |
---|
247 | pack.copyright = isNonemptyString(pack.copyright) ? |
---|
248 | (maybeRead(computePath(pack.copyright, pack.location)) || maybeRead(computePath(pack.copyright, bc.basePath)) || pack.copyright) : |
---|
249 | (pack.copyright ? bc.copyright : ""); |
---|
250 | pack.copyrightLayers = isDefined(pack.copyrightLayers) ? !!pack.copyrightLayers : bc.copyrightLayers; |
---|
251 | pack.copyrightNonlayers = isDefined(pack.copyrightNonlayers) ? !!pack.copyrightNonlayers : bc.copyrightNonlayers; |
---|
252 | |
---|
253 | // dest says where to output the compiled code stack |
---|
254 | var destPack= bc.destPackages[packName]= { |
---|
255 | name:pack.destName || packName, |
---|
256 | main:pack.destMain || pack.main, |
---|
257 | location:computePath(pack.destLocation || ("./" + (pack.destName || packName)), bc.destBasePath), |
---|
258 | packageMap:pack.destPackageMap || pack.packageMap |
---|
259 | }; |
---|
260 | require.computeMapProg(pack.destPackageMap, (destPack.mapProg= [])); |
---|
261 | delete pack.destName; |
---|
262 | delete pack.destMain; |
---|
263 | delete pack.destLocation; |
---|
264 | delete pack.destPackageMap; |
---|
265 | |
---|
266 | |
---|
267 | if (!pack.trees) { |
---|
268 | // copy the package tree; don't copy any hidden directorys (e.g., .git, .svn) or temp files |
---|
269 | pack.trees= [[pack.location, destPack.location, /(\/\.)|(~$)/]]; |
---|
270 | } // else the user has provided explicit copy instructions |
---|
271 | |
---|
272 | // filenames, dirs, trees just like global, except relative to the pack.(src|dest)Location |
---|
273 | for (var property in {files:1, dirs:1, trees:1}) { |
---|
274 | pack[property]= (pack[property] || []).map(function(item) { |
---|
275 | return cleanupFilenamePair(item, pack.location, destPack.location, property + " in package " + packName); |
---|
276 | }); |
---|
277 | } |
---|
278 | bc.packageMap[packName]= packName; |
---|
279 | bc.destPackageMap[destPack.name]= destPack.name; |
---|
280 | } |
---|
281 | |
---|
282 | bc.packages= bc.packageMap; |
---|
283 | bc.destPackages= {}; |
---|
284 | bc.packageMap= {}; |
---|
285 | bc.destPackageMap= {}; |
---|
286 | for (var packageName in bc.packages) { |
---|
287 | var pack= bc.packages[packageName]; |
---|
288 | pack.name = pack.name || packageName; |
---|
289 | processPackage(pack); |
---|
290 | } |
---|
291 | |
---|
292 | // now that we know the dojo path, we can automatically add DOH, if required |
---|
293 | if(bc.copyTests && !bc.packages.doh){ |
---|
294 | bc.packages.doh = { |
---|
295 | name:"doh", |
---|
296 | location:compactPath(bc.packages.dojo.location + "/../util/doh"), |
---|
297 | destLocation:"util/doh" |
---|
298 | }; |
---|
299 | processPackage(bc.packages.doh); |
---|
300 | } |
---|
301 | |
---|
302 | // now that bc.packageMap is initialized... |
---|
303 | require.computeMapProg(bc.packageMap, (bc.packageMapProg= [])); |
---|
304 | require.computeMapProg(bc.destPackageMap, (bc.destPackageMapProg= [])); |
---|
305 | |
---|
306 | // get this done too... |
---|
307 | require.computeMapProg(bc.paths, (bc.pathsMapProg= [])); |
---|
308 | require.computeMapProg(bc.destPaths || bc.paths, (bc.destPathsMapProg= [])); |
---|
309 | |
---|
310 | // add some methods to bc to help with resolving AMD module info |
---|
311 | bc.srcModules= {}; |
---|
312 | bc.destModules= {}; |
---|
313 | |
---|
314 | var trimLastChars= function(text, n){ |
---|
315 | return text.substring(0, text.length-n); |
---|
316 | }; |
---|
317 | |
---|
318 | bc.getSrcModuleInfo= function(mid, referenceModule, ignoreFileType) { |
---|
319 | if(ignoreFileType){ |
---|
320 | var result= require.getModuleInfo(mid+"/x", referenceModule, bc.packages, bc.srcModules, bc.basePath + "/", bc.packageMapProg, bc.pathsMapProg, true); |
---|
321 | // trim /x.js |
---|
322 | result.mid= trimLastChars(result.mid, 2); |
---|
323 | result.url= trimLastChars(result.url, 5); |
---|
324 | return result; |
---|
325 | }else{ |
---|
326 | return require.getModuleInfo(mid, referenceModule, bc.packages, bc.srcModules, bc.basePath + "/", bc.packageMapProg, bc.pathsMapProg, true); |
---|
327 | } |
---|
328 | }; |
---|
329 | |
---|
330 | bc.getDestModuleInfo= function(mid, referenceModule, ignoreFileType) { |
---|
331 | // note: bd.destPagePath should never be required; but it's included for completeness and up to the user to provide it if some transform does decide to use it |
---|
332 | if(ignoreFileType){ |
---|
333 | var result= require.getModuleInfo(mid+"/x", referenceModule, bc.destPackages, bc.destModules, bc.destBasePath + "/", bc.destPackageMapProg, bc.destPathsMapProg, true); |
---|
334 | // trim /x.js |
---|
335 | result.mid= trimLastChars(result.mid, 2); |
---|
336 | result.url= trimLastChars(result.url, 5); |
---|
337 | return result; |
---|
338 | }else{ |
---|
339 | return require.getModuleInfo(mid, referenceModule, bc.destPackages, bc.destModules, bc.destBasePath + "/", bc.destPackageMapProg, bc.destPathsMapProg, true); |
---|
340 | } |
---|
341 | }; |
---|
342 | })(); |
---|
343 | |
---|
344 | |
---|
345 | if(bc.selectorEngine && bc.defaultConfig && bc.defaultConfig.hasCache){ |
---|
346 | bc.defaultConfig.hasCache["config-selectorEngine"] = bc.selectorEngine; |
---|
347 | } |
---|
348 | |
---|
349 | (function() { |
---|
350 | // a layer is a module that should be written with all of its dependencies, as well as all modules given in |
---|
351 | // the include vector together with their dependencies, excluding modules contained in the exclude vector and their dependencies |
---|
352 | var layer, fixedLayers= {}; |
---|
353 | for (var mid in bc.layers) { |
---|
354 | layer= bc.layers[mid]; |
---|
355 | layer.exclude= layer.exclude || []; |
---|
356 | layer.include= layer.include || []; |
---|
357 | layer.boot = !!layer.boot; |
---|
358 | layer.discard = !!layer.discard; |
---|
359 | |
---|
360 | var tlm = mid.split("/")[0], |
---|
361 | pack = bc.packages[tlm], |
---|
362 | packLocation = pack && pack.location, |
---|
363 | packCopyright = pack && pack.copyright, |
---|
364 | packCopyrightLayers = pack && pack.copyrightLayers; |
---|
365 | if(isNonemptyString(layer.copyright)){ |
---|
366 | // if relative, first try basePath, then try package location, otherwise, just use what's given |
---|
367 | layer.copyright = (packLocation && maybeRead(computePath(layer.copyright, packLocation))) || maybeRead(computePath(layer.copyright, bc.basePath)) || layer.copyright; |
---|
368 | }else if(isDefined(layer.copyright)){ |
---|
369 | // some kind of truthy other than a string |
---|
370 | layer.copyright = layer.copyright ? (packCopyright || bc.copyright) : ""; |
---|
371 | }else{ |
---|
372 | layer.copyright = pack ? (packCopyrightLayers && (packCopyright || bc.copyright)) : (bc.copyrightLayers && bc.copyright); |
---|
373 | } |
---|
374 | if(!layer.copyright){ |
---|
375 | layer.copyright = ""; |
---|
376 | } |
---|
377 | fixedLayers[mid]= layer; |
---|
378 | } |
---|
379 | bc.layers= fixedLayers; |
---|
380 | |
---|
381 | // if (and only if) we're doing a build that includes the dojo tree, then ensure the loader layer is defined correctly |
---|
382 | // and make sure all other layers exclude the loader unless they are marked with custome base |
---|
383 | if(bc.packages.dojo){ |
---|
384 | if(!bc.layers["dojo/dojo"]){ |
---|
385 | bc.layers["dojo/dojo"] = {name:"dojo/dojo", copyright:bc.defaultCopyright + bc.defaultBuildNotice, include:["dojo/main"], exclude:[]}; |
---|
386 | } |
---|
387 | for(var p in bc.layers){ |
---|
388 | layer = bc.layers[p]; |
---|
389 | if(p=="dojo/dojo"){ |
---|
390 | if(!layer.customBase){ |
---|
391 | // the purpose of the layer is to simply add some additional modules to a standard dojo boot |
---|
392 | if(layer.include.indexOf("dojo/main")==-1){ |
---|
393 | layer.include.push("dojo/main"); |
---|
394 | } |
---|
395 | }else{ |
---|
396 | // this is a custom base dojo.js; it's up the the user to say exactly what they want |
---|
397 | } |
---|
398 | }else{ |
---|
399 | if((layer.boot || !layer.customBase) && layer.exclude.indexOf("dojo/dojo")==-1){ |
---|
400 | // the layer has dojo/dojo if it is booting, or assumes dojo/dojo if its not explicitly saying customBase |
---|
401 | layer.exclude.push("dojo/dojo"); |
---|
402 | } |
---|
403 | // by definition... |
---|
404 | layer.customBase = layer.boot; |
---|
405 | } |
---|
406 | } |
---|
407 | } |
---|
408 | |
---|
409 | })(); |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | bc.locales= bc.locales || []; |
---|
414 | |
---|
415 | // for the static has flags, -1 means its not static; this gives a way of combining several static has flag sets |
---|
416 | // and still allows later sets to delete flags set in earlier sets |
---|
417 | var deleteStaticHasFlagSet= []; |
---|
418 | for (var p in bc.staticHasFeatures) if (bc.staticHasFeatures[p]==-1) deleteStaticHasFlagSet.push(p); |
---|
419 | deleteStaticHasFlagSet.forEach(function(flag){delete bc.staticHasFeatures[flag];}); |
---|
420 | |
---|
421 | if(bc.action){ |
---|
422 | bc.action.split(/\W|\s/).forEach(function(action){ |
---|
423 | action= action.match(/\s*(\S+)\s*/)[1]; |
---|
424 | switch(action){ |
---|
425 | case "check": |
---|
426 | bc.check= true; |
---|
427 | break; |
---|
428 | case "clean": |
---|
429 | bc.clean= true; |
---|
430 | break; |
---|
431 | case "release": |
---|
432 | bc.release= true; |
---|
433 | break; |
---|
434 | default: |
---|
435 | bc.log("inputUnknownAction", ["action", action]); |
---|
436 | } |
---|
437 | }); |
---|
438 | } |
---|
439 | |
---|
440 | if(bc.clean){ |
---|
441 | bc.log("cleanRemoved"); |
---|
442 | } |
---|
443 | |
---|
444 | // understand stripConsole from dojo 1.3 and before |
---|
445 | var stripConsole= bc.stripConsole; |
---|
446 | if (!stripConsole || stripConsole=="none") { |
---|
447 | stripConsole= false; |
---|
448 | } else if (stripConsole == "normal,warn") { |
---|
449 | bc.log("inputDeprecatedStripConsole", ["deprecated", "normal,warn", "use", "warn"]); |
---|
450 | stripConsole = "warn"; |
---|
451 | } else if (stripConsole == "normal,error") { |
---|
452 | bc.log("inputDeprecatedStripConsole", ["deprecated", "normal,error", "use", "all"]); |
---|
453 | stripConsole = "all"; |
---|
454 | } else if (!/normal|warn|all|none/.test(stripConsole)){ |
---|
455 | bc.log("inputUnknownStripConsole", ["value", stripConsole]); |
---|
456 | } |
---|
457 | bc.stripConsole= stripConsole; |
---|
458 | |
---|
459 | function fixupOptimize(value){ |
---|
460 | if(value){ |
---|
461 | value= value + ""; |
---|
462 | value= value.toLowerCase(); |
---|
463 | if(!/^(comments|shrinksafe(\.keeplines)?|closure(\.keeplines)?)$/.test(value)){ |
---|
464 | bc.log("inputUnknownOptimize", ["value", value]); |
---|
465 | value = 0; |
---|
466 | }else{ |
---|
467 | if(/shrinksafe/.test(value) && stripConsole){ |
---|
468 | value+= "." + stripConsole; |
---|
469 | } |
---|
470 | } |
---|
471 | } |
---|
472 | return value; |
---|
473 | } |
---|
474 | bc.optimize = fixupOptimize(bc.optimize); |
---|
475 | bc.layerOptimize = fixupOptimize(bc.layerOptimize); |
---|
476 | |
---|
477 | (function(){ |
---|
478 | var fixedScopeMap = {dojo:"dojo", dijit:"dijit", dojox:"dojox"}; |
---|
479 | (bc.scopeMap || []).forEach(function(pair){ |
---|
480 | fixedScopeMap[pair[0]] = pair[1]; |
---|
481 | }); |
---|
482 | bc.scopeMap = fixedScopeMap; |
---|
483 | |
---|
484 | bc.scopeNames = []; |
---|
485 | for(var p in fixedScopeMap){ |
---|
486 | bc.scopeNames.push(p); |
---|
487 | } |
---|
488 | })(); |
---|
489 | |
---|
490 | var fixedInternStringsSkipList = {}; |
---|
491 | (bc.internSkipList || bc.internStringsSkipList || []).forEach(function(mid){ |
---|
492 | if(/.*\..*\./.test(mid)){ |
---|
493 | bc.log("possibleLegacyModuleId", ["name", mid]); |
---|
494 | } |
---|
495 | fixedInternStringsSkipList[mid] = 1; |
---|
496 | }); |
---|
497 | bc.internStringsSkipList = fixedInternStringsSkipList; |
---|
498 | |
---|
499 | var deprecated= []; |
---|
500 | for(p in bc){ |
---|
501 | if(/^(loader|xdDojoPath|scopeDjConfig|xdScopeArgs|xdDojoScopeName|expandProvide|buildLayers|query|removeDefaultNameSpaces|addGuards)$/.test(p)){ |
---|
502 | deprecated.push(p); |
---|
503 | bc.log("inputDeprecated", ["switch", p]); |
---|
504 | } |
---|
505 | } |
---|
506 | deprecated.forEach(function(p){ |
---|
507 | delete bc[p]; |
---|
508 | }); |
---|
509 | |
---|
510 | // dump bc (if requested) before changing gate names to gate ids below |
---|
511 | if(bc.check){ |
---|
512 | (function() { |
---|
513 | var toDump = { |
---|
514 | basePath:1, |
---|
515 | buildFlags:1, |
---|
516 | buildReportDir:1, |
---|
517 | buildReportFilename:1, |
---|
518 | closureCompilerPath:1, |
---|
519 | compactCssSet:1, |
---|
520 | copyright:1, |
---|
521 | copyrightLayers:1, |
---|
522 | copyrightNonlayers:1, |
---|
523 | copyTests:1, |
---|
524 | destBasePath:1, |
---|
525 | destModules:1, |
---|
526 | destPackageMap:1, |
---|
527 | destPackageMapProg:1, |
---|
528 | destPackages:1, |
---|
529 | destPathTransforms:1, |
---|
530 | destPathsMapProg:1, |
---|
531 | dirs:1, |
---|
532 | discoveryProcs:1, |
---|
533 | files:1, |
---|
534 | internStringsSkipList:1, |
---|
535 | layers:1, |
---|
536 | locales:1, |
---|
537 | maxOptimizationProcesses:1, |
---|
538 | mini:1, |
---|
539 | "package":1, |
---|
540 | packageMap:1, |
---|
541 | packageMapProg:1, |
---|
542 | packages:1, |
---|
543 | paths:1, |
---|
544 | pathsMapProg:1, |
---|
545 | plugins:1, |
---|
546 | replacements:1, |
---|
547 | startTimestamp:1, |
---|
548 | staticHasFeatures:1, |
---|
549 | stripConsole:1, |
---|
550 | trees:1 |
---|
551 | }; |
---|
552 | for(var p in toDump){ |
---|
553 | toDump[p] = bc[p]; |
---|
554 | } |
---|
555 | bc.log("pacify", stringify(toDump)); |
---|
556 | })(); |
---|
557 | bc.release = 0; |
---|
558 | } |
---|
559 | |
---|
560 | if(bc.writeProfile){ |
---|
561 | |
---|
562 | } |
---|
563 | |
---|
564 | if(bc.debugCheck){ |
---|
565 | (function(){ |
---|
566 | var toDump = {}; |
---|
567 | for(var p in bc){ |
---|
568 | if(bc[p]!==messages[p] && typeof bc[p]!="function"){ |
---|
569 | toDump[p] = bc[p]; |
---|
570 | } |
---|
571 | } |
---|
572 | console.log("profile:"); |
---|
573 | console.log(stringify(toDump)); |
---|
574 | toDump = {}; |
---|
575 | for(p in require){ |
---|
576 | if(p!="modules" && p!="module" && p!="rawConfig" && typeof require[p]!="function"){ |
---|
577 | toDump[p] = require[p]; |
---|
578 | } |
---|
579 | } |
---|
580 | console.log("require config:"); |
---|
581 | console.log(stringify(toDump)); |
---|
582 | })(); |
---|
583 | bc.release = 0; |
---|
584 | } |
---|
585 | |
---|
586 | // clean up the gates and transforms |
---|
587 | (function() { |
---|
588 | // check that each transform references a valid gate |
---|
589 | for (var gates= {}, i= 0; i<bc.gates.length; i++) { |
---|
590 | gates[bc.gates[i][1]]= i; |
---|
591 | } |
---|
592 | var |
---|
593 | transforms= bc.transforms, |
---|
594 | gateId; |
---|
595 | for (var transformId in transforms) { |
---|
596 | // each item is a [AMD-MID, gateName] pair |
---|
597 | gateId= gates[transforms[transformId][1]]; |
---|
598 | if (typeof gateId == "undefined") { |
---|
599 | bc.log("inputUnknownGate", ["transform", transformId, "gate", transforms[transformId][1]]); |
---|
600 | } else { |
---|
601 | transforms[transformId][1]= gateId; |
---|
602 | } |
---|
603 | } |
---|
604 | })(); |
---|
605 | |
---|
606 | // clean up the transformJobs |
---|
607 | (function() { |
---|
608 | // check that that each transformId referenced in transformJobs references an existing item in transforms |
---|
609 | // ensure proper gate order of the transforms given in transformJobs; do not disturb order within a given |
---|
610 | // gate--this is the purview of the user |
---|
611 | var transforms= bc.transforms; |
---|
612 | bc.transformJobs.forEach(function(item) { |
---|
613 | // item is a [predicate, vector of transformId] pairs |
---|
614 | var error= false; |
---|
615 | var tlist= item[1].map(function(id) { |
---|
616 | // item is a transformId |
---|
617 | if (transforms[id]) { |
---|
618 | // return a [trandformId, gateId] pair |
---|
619 | return [id, transforms[id][1]]; |
---|
620 | } else { |
---|
621 | error= true; |
---|
622 | bc.log("inputUnknownTransform", ["transform", id]); |
---|
623 | return 0; |
---|
624 | } |
---|
625 | }); |
---|
626 | // tlist is a vector of [transformId, gateId] pairs than need to be checked for order |
---|
627 | if (!error) { |
---|
628 | for (var i= 0, end= tlist.length - 1; i<end;) { |
---|
629 | if (tlist[i][1]>tlist[i+1][1]) { |
---|
630 | var t= tlist[i]; |
---|
631 | tlist[i]= tlist[i+1]; |
---|
632 | tlist[i+1]= t; |
---|
633 | i && i--; |
---|
634 | } else { |
---|
635 | i++; |
---|
636 | } |
---|
637 | } |
---|
638 | // now replace the vector of transformIds with the sorted list |
---|
639 | item[1]= tlist; |
---|
640 | } |
---|
641 | }); |
---|
642 | })(); |
---|
643 | |
---|
644 | if (argv.args.unitTest=="dumpbc") { |
---|
645 | console.log(stringify(bc) + "\n"); |
---|
646 | } |
---|
647 | |
---|
648 | if(bc.quiet){ |
---|
649 | (function(){ |
---|
650 | var delSet = {}; |
---|
651 | for(var p in bc.pacifySet){ |
---|
652 | if(bc.messageMap[p][1]>199){ |
---|
653 | delSet[p] = 1; |
---|
654 | } |
---|
655 | } |
---|
656 | for(p in delSet){ |
---|
657 | delete bc.pacifySet[p]; |
---|
658 | } |
---|
659 | })(); |
---|
660 | } |
---|
661 | |
---|
662 | if(bc.unitTestComputedProfile){ |
---|
663 | bc.unitTestComputedProfile(); |
---|
664 | // stop the build |
---|
665 | bc.release = 0; |
---|
666 | } |
---|
667 | |
---|
668 | if(!bc.unitTestComputedProfile && !bc.check && !bc.debugCheck && !bc.clean && !bc.release){ |
---|
669 | bc.log("pacify", "Nothing to do; you must explicitly instruct the application to do something; use the option --help for help."); |
---|
670 | } |
---|
671 | |
---|
672 | return bc; |
---|
673 | }); |
---|