1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Refactor boot process to allow for lack of wiki folder

Previously, the command line interface required a wiki folder to be
specified.

This is part of the work to enable TiddlyWiki5 to be used more easily
as a library in other node.js apps
This commit is contained in:
Jeremy Ruston 2013-08-21 09:42:51 +01:00
parent d4a571ae79
commit 9345078926
2 changed files with 14 additions and 6 deletions

View File

@ -28,7 +28,7 @@ In practice, each module is wrapped in a separate script block.
/////////////////////////// Setting up $tw /////////////////////////// Setting up $tw
// Set up $tw global for the server // Set up $tw global for the server (set up for browser is in bootprefix.js)
if(typeof(window) === "undefined") { if(typeof(window) === "undefined") {
global.$tw = global.$tw || {}; // No `browser` member for the server global.$tw = global.$tw || {}; // No `browser` member for the server
exports.$tw = $tw; // Export $tw for when boot.js is required directly in node.js exports.$tw = $tw; // Export $tw for when boot.js is required directly in node.js
@ -1248,6 +1248,8 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
}); });
} }
}); });
// Save the path to the tiddlers folder for the filesystemadaptor
$tw.boot.wikiTiddlersPath = path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir);
// Load any plugins within the wiki folder // Load any plugins within the wiki folder
var wikiPluginsPath = path.resolve(wikiPath,$tw.config.wikiPluginsSubDir); var wikiPluginsPath = path.resolve(wikiPath,$tw.config.wikiPluginsSubDir);
if(fs.existsSync(wikiPluginsPath)) { if(fs.existsSync(wikiPluginsPath)) {
@ -1281,7 +1283,9 @@ $tw.loadTiddlers = function() {
// Load the core tiddlers // Load the core tiddlers
$tw.wiki.addTiddler($tw.loadPluginFolder($tw.boot.corePath)); $tw.wiki.addTiddler($tw.loadPluginFolder($tw.boot.corePath));
// Load the tiddlers from the wiki directory // Load the tiddlers from the wiki directory
$tw.boot.wikiInfo = $tw.loadWikiTiddlers($tw.boot.wikiPath); if($tw.boot.wikiPath) {
$tw.boot.wikiInfo = $tw.loadWikiTiddlers($tw.boot.wikiPath);
}
}; };
// End of if(!$tw.browser) // End of if(!$tw.browser)
@ -1317,14 +1321,15 @@ $tw.boot.startup = function() {
// If the first command line argument doesn't start with `--` then we // 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 // interpret it as the path to the wiki folder, which will otherwise default
// to the current folder // to the current folder
$tw.boot.argv = Array.prototype.slice.call(process.argv,2); if($tw.boot.argv[0] === "*") {
if($tw.boot.argv[0] && $tw.boot.argv[0].indexOf("--") !== 0) { $tw.boot.wikiPath = undefined;
$tw.boot.argv = $tw.boot.argv.slice(1);
} else if($tw.boot.argv[0] && $tw.boot.argv[0].indexOf("--") !== 0) {
$tw.boot.wikiPath = $tw.boot.argv[0]; $tw.boot.wikiPath = $tw.boot.argv[0];
$tw.boot.argv = $tw.boot.argv.slice(1); $tw.boot.argv = $tw.boot.argv.slice(1);
} else { } else {
$tw.boot.wikiPath = process.cwd(); $tw.boot.wikiPath = process.cwd();
} }
$tw.boot.wikiTiddlersPath = path.resolve($tw.boot.wikiPath,$tw.config.wikiTiddlersSubDir);
// Read package info // Read package info
$tw.packageInfo = require("../package"); $tw.packageInfo = require("../package");
// Check node version number // Check node version number

View File

@ -4,7 +4,10 @@
This is invoked as a shell script by NPM when the `tiddlywiki` command is typed This is invoked as a shell script by NPM when the `tiddlywiki` command is typed
*/ */
var tiddlywiki = require("./boot/boot.js"); var $tw = require("./boot/boot.js").$tw;
// Pass the command line arguments to the boot kernel
$tw.boot.argv = Array.prototype.slice.call(process.argv,2);
// Boot the TW5 app // Boot the TW5 app
$tw.boot.boot(); $tw.boot.boot();