Debian Codegraph @

util/build/buildControl.js

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