1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

More tidying up of boot.js

This commit is contained in:
Jeremy Ruston 2013-03-22 20:02:19 +00:00
parent e336e0661c
commit ed07798c29

View File

@ -42,6 +42,15 @@ if(!$tw.browser) {
$tw.utils = $tw.utils || {}; $tw.utils = $tw.utils || {};
$tw.boot = $tw.boot || {}; $tw.boot = $tw.boot || {};
/////////////////////////// Standard node.js libraries
var fs, path, vm;
if(!$tw.browser) {
fs = require("fs");
path = require("path");
vm = require("vm");
}
/////////////////////////// Utility functions /////////////////////////// Utility functions
/* /*
@ -1015,69 +1024,78 @@ $tw.loadTiddlers = function() {
// End of if(!$tw.browser) // End of if(!$tw.browser)
} }
/////////////////////////// Starting up /////////////////////////// Main startup function called once tiddlers have been decrypted
/*
Main startup function that is called once tiddlers have been decrypted
*/
$tw.boot.startup = function() { $tw.boot.startup = function() {
if(!$tw.browser) {
// Modules store registers all the modules the system has seen // System paths and filenames
$tw.modules = $tw.modules || {}; $tw.boot.bootFile = path.basename(module.filename);
$tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:} $tw.boot.bootPath = path.dirname(module.filename);
$tw.modules.types = $tw.modules.types || {}; // hashmap by module type of hashmap of exports // If the first command line argument doesn't start with `--` then we
// interpret it as the path to the wiki folder, which will otherwise default
// Config object // to the current folder
$tw.config = $tw.config || {}; $tw.boot.argv = Array.prototype.slice.call(process.argv,2);
if($tw.boot.argv[0] && $tw.boot.argv[0].indexOf("--") !== 0) {
// Constants $tw.boot.wikiPath = $tw.boot.argv[0];
$tw.config.pluginsPath = "../plugins/"; $tw.boot.argv = $tw.boot.argv.slice(1);
$tw.config.wikiInfo = $tw.config.wikiInfo || "./tiddlywiki.info"; } else {
$tw.config.wikiPluginsSubDir = $tw.config.wikiPluginsSubDir || "./plugins"; $tw.boot.wikiPath = process.cwd();
$tw.config.wikiSystemSubDir = $tw.config.wikiSystemSubDir || "./wiki"; }
$tw.config.wikiTiddlersSubDir = $tw.config.wikiTiddlersSubDir || "./tiddlers"; // Read package info
$tw.packageInfo = JSON.parse(fs.readFileSync($tw.boot.bootPath + "/../package.json"));
$tw.config.jsModuleHeaderRegExpString = "^\\/\\*\\\\\\n((?:^[^\\n]*\\n)+?)(^\\\\\\*\\/$\\n?)"; // Check node version number
if($tw.utils.checkVersions($tw.packageInfo.engines.node.substr(2),process.version.substr(1))) {
// File extension mappings throw "TiddlyWiki5 requires node.js version " + $tw.packageInfo.engine.node;
$tw.config.fileExtensionInfo = { }
".tid": {type: "application/x-tiddler"}, }
".tiddler": {type: "application/x-tiddler-html-div"}, // Initialise some more $tw properties
".recipe": {type: "application/vnd.tiddlywiki2-recipe"}, $tw.utils.deepDefaults($tw,{
".txt": {type: "text/plain"}, modules: { // Information about each module
".css": {type: "text/css"}, titles: {}, // hashmap by module title of {fn:, exports:, moduleType:}
".html": {type: "text/html"}, types: {} // hashmap by module type of hashmap of exports
".js": {type: "application/javascript"}, },
".json": {type: "application/json"}, config: { // Configuration overridables
".pdf": {type: "application/pdf"}, pluginsPath: "../plugins/",
".jpg": {type: "image/jpeg"}, wikiInfo: "./tiddlywiki.info",
".jpeg": {type: "image/jpeg"}, wikiPluginsSubDir: "./plugins",
".png": {type: "image/png"}, wikiSystemSubDir: "./wiki",
".gif": {type: "image/gif"}, wikiTiddlersSubDir: "./tiddlers",
".svg": {type: "image/svg+xml"} jsModuleHeaderRegExpString: "^\\/\\*\\\\\\n((?:^[^\\n]*\\n)+?)(^\\\\\\*\\/$\\n?)",
}; fileExtensionInfo: { // File extension mappings
".tid": {type: "application/x-tiddler"},
// Content type mappings ".tiddler": {type: "application/x-tiddler-html-div"},
$tw.config.contentTypeInfo = { ".recipe": {type: "application/vnd.tiddlywiki2-recipe"},
"text/vnd.tiddlywiki": {encoding: "utf8", extension: ".tid"}, ".txt": {type: "text/plain"},
"application/x-tiddler": {encoding: "utf8", extension: ".tid"}, ".css": {type: "text/css"},
"application/x-tiddler-html-div": {encoding: "utf8", extension: ".tiddler"}, ".html": {type: "text/html"},
"application/vnd.tiddlywiki2-recipe": {encoding: "utf8", extension: ".recipe"}, ".js": {type: "application/javascript"},
"text/plain": {encoding: "utf8", extension: ".txt"}, ".json": {type: "application/json"},
"text/css": {encoding: "utf8", extension: ".css"}, ".pdf": {type: "application/pdf"},
"text/html": {encoding: "utf8", extension: ".html"}, ".jpg": {type: "image/jpeg"},
"application/javascript": {encoding: "utf8", extension: ".js"}, ".jpeg": {type: "image/jpeg"},
"application/json": {encoding: "utf8", extension: ".json"}, ".png": {type: "image/png"},
"application/pdf": {encoding: "base64", extension: ".pdf"}, ".gif": {type: "image/gif"},
"image/jpeg": {encoding: "base64", extension: ".jpg"}, ".svg": {type: "image/svg+xml"}
"image/png": {encoding: "base64", extension: ".png"}, },
"image/gif": {encoding: "base64", extension: ".gif"}, contentTypeInfo: {
"image/svg+xml": {encoding: "utf8", extension: ".svg"} "text/vnd.tiddlywiki": {encoding: "utf8", extension: ".tid"},
}; "application/x-tiddler": {encoding: "utf8", extension: ".tid"},
"application/x-tiddler-html-div": {encoding: "utf8", extension: ".tiddler"},
/* "application/vnd.tiddlywiki2-recipe": {encoding: "utf8", extension: ".recipe"},
Create the wiki store for the app "text/plain": {encoding: "utf8", extension: ".txt"},
*/ "text/css": {encoding: "utf8", extension: ".css"},
"text/html": {encoding: "utf8", extension: ".html"},
"application/javascript": {encoding: "utf8", extension: ".js"},
"application/json": {encoding: "utf8", extension: ".json"},
"application/pdf": {encoding: "base64", extension: ".pdf"},
"image/jpeg": {encoding: "base64", extension: ".jpg"},
"image/png": {encoding: "base64", extension: ".png"},
"image/gif": {encoding: "base64", extension: ".gif"},
"image/svg+xml": {encoding: "utf8", extension: ".svg"}
}
}
});
// Create the wiki store for the app
$tw.wiki = new $tw.Wiki(); $tw.wiki = new $tw.Wiki();
// Install built in tiddler fields modules // Install built in tiddler fields modules
$tw.Tiddler.fieldModules = $tw.modules.getModulesByTypeAsHashmap("tiddlerfield"); $tw.Tiddler.fieldModules = $tw.modules.getModulesByTypeAsHashmap("tiddlerfield");
@ -1102,38 +1120,7 @@ $tw.config.contentTypeInfo = {
}); });
}; };
/* /////////////////////////// Decrypt tiddlers and then startup
Initialise crypto and then startup
*/
/////////////////////////// Server initialisation
var fs, path, vm;
if(!$tw.browser) {
// Standard node libraries
fs = require("fs");
path = require("path");
vm = require("vm");
// System paths and filenames
$tw.boot.bootFile = path.basename(module.filename);
$tw.boot.bootPath = path.dirname(module.filename);
// If the first command line argument doesn't start with `--` then we
// interpret it as the path to the wiki folder, which will otherwise default
// to the current folder
$tw.boot.argv = Array.prototype.slice.call(process.argv,2);
if($tw.boot.argv[0] && $tw.boot.argv[0].indexOf("--") !== 0) {
$tw.boot.wikiPath = $tw.boot.argv[0];
$tw.boot.argv = $tw.boot.argv.slice(1);
} else {
$tw.boot.wikiPath = process.cwd();
}
// Read package info
$tw.packageInfo = JSON.parse(fs.readFileSync($tw.boot.bootPath + "/../package.json"));
// Check node version number
if($tw.utils.checkVersions($tw.packageInfo.engines.node.substr(2),process.version.substr(1))) {
throw "TiddlyWiki5 requires node.js version " + $tw.packageInfo.engine.node;
}
}
// Initialise crypto object // Initialise crypto object
$tw.crypto = new $tw.utils.Crypto(); $tw.crypto = new $tw.utils.Crypto();
@ -1141,8 +1128,9 @@ $tw.crypto = new $tw.utils.Crypto();
if($tw.browser) { if($tw.browser) {
$tw.passwordPrompt = new $tw.utils.PasswordPrompt(); $tw.passwordPrompt = new $tw.utils.PasswordPrompt();
} }
// Get any encrypted tiddlers // Preload any encrypted tiddlers
$tw.boot.decryptEncryptedTiddlers(function() { $tw.boot.decryptEncryptedTiddlers(function() {
// Startup
$tw.boot.startup(); $tw.boot.startup();
}); });