1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 17:40:29 +00:00
TiddlyWiki5/tiddlywiki5/BootLoader.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

(function() {
/*jslint node: true */
"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;
2011-12-21 13:03:37 +00:00
// If the destination starts with ./ then it's a relative reference to an ordinary module
if(dstModule.substr(0,2) === "./" ) {
// 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("/");
} else {
// If there was no / or ./ then it's a built in module and the name doesn't need resolving
return dstModule;
}
}
/*
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);
},
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:48:11 +00:00
if(module.exports) {
return module.exports;
} else {
2011-12-21 13:03:37 +00:00
module.exports = {};
module.module(require,module.exports,module);
return module.exports;
}
}
2012-01-03 17:41:54 +00:00
// Execute the main module
var app = new (executeModule("js/App.js").App)();
})();