1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-18 20:10:02 +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,32 +1024,44 @@ $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 = { }
}
// Initialise some more $tw properties
$tw.utils.deepDefaults($tw,{
modules: { // Information about each module
titles: {}, // hashmap by module title of {fn:, exports:, moduleType:}
types: {} // hashmap by module type of hashmap of exports
},
config: { // Configuration overridables
pluginsPath: "../plugins/",
wikiInfo: "./tiddlywiki.info",
wikiPluginsSubDir: "./plugins",
wikiSystemSubDir: "./wiki",
wikiTiddlersSubDir: "./tiddlers",
jsModuleHeaderRegExpString: "^\\/\\*\\\\\\n((?:^[^\\n]*\\n)+?)(^\\\\\\*\\/$\\n?)",
fileExtensionInfo: { // File extension mappings
".tid": {type: "application/x-tiddler"}, ".tid": {type: "application/x-tiddler"},
".tiddler": {type: "application/x-tiddler-html-div"}, ".tiddler": {type: "application/x-tiddler-html-div"},
".recipe": {type: "application/vnd.tiddlywiki2-recipe"}, ".recipe": {type: "application/vnd.tiddlywiki2-recipe"},
@ -1055,10 +1076,8 @@ $tw.config.fileExtensionInfo = {
".png": {type: "image/png"}, ".png": {type: "image/png"},
".gif": {type: "image/gif"}, ".gif": {type: "image/gif"},
".svg": {type: "image/svg+xml"} ".svg": {type: "image/svg+xml"}
}; },
contentTypeInfo: {
// Content type mappings
$tw.config.contentTypeInfo = {
"text/vnd.tiddlywiki": {encoding: "utf8", extension: ".tid"}, "text/vnd.tiddlywiki": {encoding: "utf8", extension: ".tid"},
"application/x-tiddler": {encoding: "utf8", extension: ".tid"}, "application/x-tiddler": {encoding: "utf8", extension: ".tid"},
"application/x-tiddler-html-div": {encoding: "utf8", extension: ".tiddler"}, "application/x-tiddler-html-div": {encoding: "utf8", extension: ".tiddler"},
@ -1073,11 +1092,10 @@ $tw.config.contentTypeInfo = {
"image/png": {encoding: "base64", extension: ".png"}, "image/png": {encoding: "base64", extension: ".png"},
"image/gif": {encoding: "base64", extension: ".gif"}, "image/gif": {encoding: "base64", extension: ".gif"},
"image/svg+xml": {encoding: "utf8", extension: ".svg"} "image/svg+xml": {encoding: "utf8", extension: ".svg"}
}; }
}
/* });
Create the wiki store for the app // 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();
}); });