topical media & game development

talk show tell print

mobile-query-three-plugins-requirejs-bin-tomainconfigfile.js / js



  // declare a fake requirejs.config() function to merge all calls in a single options object
  var output        = {}
  var requirejs        = {};
  requirejs.config        = function(opts){
          // merge opts in output with deep copy
          deepExtend(output, opts)        
          
          // from http://andrewdupont.net/2009/08/28/deep-extending-objects-in-javascript/
  	function deepExtend(dst, src){
                  for (var property in src) {
                          if (src[property] && src[property].constructor && src[property].constructor === Object) {
                                  dst[property] = dst[property] || {};
                                  arguments.callee(dst[property], src[property]);
                          } else {
                                  dst[property] = src[property];
                          }
                  }
                  return dst;
          };
  }
  
  // get all filenames in confrequire/*.conrequire.js
  var filenames        = require('fs').readdirSync('confrequire').filter(function(filename){
          return filename.match(/\.confrequire\.js/)
  });
  // concat head.confrequire.js and all confrequire/*.configrequire.js
  var content        = require('fs').readFileSync('head.confrequire.js', 'utf8')
  filenames.forEach(function(filename){
          content        += require('fs').readFileSync('confrequire/'+filename, 'utf8')
  })
  
  // eval every *.confrequire.js config
  eval(content)
  // output the merged options object for requirejs.config()
  console.log('requirejs.config('+JSON.stringify(output, null, '\t')+');')
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.