2011-12-13 12:30:09 +00:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
/*jslint node: true */
|
2012-01-14 17:23:43 +00:00
|
|
|
/*global modules: false */
|
2011-12-13 12:30:09 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Given the absolute path of a srcModule, and a relative reference to a dstModule, return the fully resolved module name
|
|
|
|
*/
|
|
|
|
function resolveModuleName(srcModule,dstModule) {
|
|
|
|
var src = srcModule.split("/"),
|
|
|
|
dst = dstModule.split("/"),
|
|
|
|
c;
|
2012-01-07 17:31:57 +00:00
|
|
|
// If the destination starts with ./ or ../ then it's a relative reference to an ordinary module
|
|
|
|
if(dstModule.substr(0,2) === "./" || dstModule.substr(0,3) === "../" ) {
|
2011-12-13 12:30:09 +00:00
|
|
|
// Remove the filename part of the src path
|
|
|
|
src.splice(src.length-1,1);
|
|
|
|
// Process the destination path bit by bit
|
|
|
|
while(dst.length > 0) {
|
|
|
|
c = dst.shift();
|
|
|
|
switch(c) {
|
|
|
|
case ".": // Ignore dots
|
|
|
|
break;
|
|
|
|
case "..": // Slice off the last src directory for a double dot
|
|
|
|
src.splice(src.length-1,1);
|
|
|
|
break;
|
|
|
|
default: // Copy everything else across
|
|
|
|
src.push(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return src.join("/");
|
2011-12-21 13:03:37 +00:00
|
|
|
// If the destination starts with "/" then it's an absolute path
|
|
|
|
} else if(dstModule.substr(0,1) === "/") {
|
|
|
|
return dst.join("/");
|
2011-12-13 12:30:09 +00:00
|
|
|
} else {
|
2012-01-07 17:31:57 +00:00
|
|
|
// If there was no / or ./ or ../ then it's a built in module and the name doesn't need resolving
|
2011-12-13 12:30:09 +00:00
|
|
|
return dstModule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 10:42:19 +00:00
|
|
|
/*
|
|
|
|
Execute the module named 'modName'. The name can optionally be relative to the module named 'modRoot'
|
|
|
|
*/
|
|
|
|
function executeModule(modName,modRoot) {
|
|
|
|
var name = modRoot ? resolveModuleName(modRoot,modName) : modName,
|
|
|
|
require = function(modRequire) {
|
|
|
|
return executeModule(modRequire,name);
|
2011-12-13 12:30:09 +00:00
|
|
|
},
|
|
|
|
exports = {},
|
|
|
|
module = modules[name];
|
|
|
|
if(!module) {
|
2011-12-21 13:03:37 +00:00
|
|
|
throw new Error("Cannot find module named '" + modName + "' required by module '" + modRoot + "', resolved to " + name);
|
2011-12-13 12:30:09 +00:00
|
|
|
}
|
2011-12-13 12:48:11 +00:00
|
|
|
if(module.exports) {
|
2011-12-13 12:30:09 +00:00
|
|
|
return module.exports;
|
|
|
|
} else {
|
2011-12-21 13:03:37 +00:00
|
|
|
module.exports = {};
|
|
|
|
module.module(require,module.exports,module);
|
|
|
|
return module.exports;
|
2011-12-13 12:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 17:41:54 +00:00
|
|
|
// Execute the main module
|
|
|
|
var app = new (executeModule("js/App.js").App)();
|
2011-12-13 12:30:09 +00:00
|
|
|
|
|
|
|
})();
|