1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Add ability to load plugins via the command line

Fixes #3907
This commit is contained in:
Jermolene 2019-04-12 18:09:16 +01:00
parent 9b72eabd1a
commit 8c72a28f0c
2 changed files with 29 additions and 4 deletions

View File

@ -1855,8 +1855,10 @@ $tw.loadPlugin = function(name,paths) {
var pluginFields = $tw.loadPluginFolder(pluginPath); var pluginFields = $tw.loadPluginFolder(pluginPath);
if(pluginFields) { if(pluginFields) {
$tw.wiki.addTiddler(pluginFields); $tw.wiki.addTiddler(pluginFields);
return;
} }
} }
console.log("Warning: Cannot find plugin '" + name + "'");
}; };
/* /*
@ -1870,7 +1872,7 @@ $tw.getLibraryItemSearchPaths = function(libraryPath,envVar) {
if(env) { if(env) {
env.split(path.delimiter).map(function(item) { env.split(path.delimiter).map(function(item) {
if(item) { if(item) {
pluginPaths.push(item) pluginPaths.push(item);
} }
}); });
} }
@ -2006,6 +2008,14 @@ $tw.loadTiddlersNode = 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 any extra plugins
$tw.utils.each($tw.boot.extraPlugins,function(name) {
var parts = name.split("/"),
type = parts[0];
if(parts.length === 3 && ["plugins","themes","languages"].indexOf(type) !== -1) {
$tw.loadPlugins([parts[1] + "/" + parts[2]],$tw.config[type + "Path"],$tw.config[type + "EnvVar"]);
}
});
// Load the tiddlers from the wiki directory // Load the tiddlers from the wiki directory
if($tw.boot.wikiPath) { if($tw.boot.wikiPath) {
$tw.boot.wikiInfo = $tw.loadWikiTiddlers($tw.boot.wikiPath); $tw.boot.wikiInfo = $tw.loadWikiTiddlers($tw.boot.wikiPath);
@ -2069,6 +2079,12 @@ $tw.boot.startup = function(options) {
if($tw.boot.argv.length === 0) { if($tw.boot.argv.length === 0) {
$tw.boot.argv = ["--help"]; $tw.boot.argv = ["--help"];
} }
// Parse any extra plugin references
$tw.boot.extraPlugins = $tw.boot.extraPlugins || [];
while($tw.boot.argv[0] && $tw.boot.argv[0].indexOf("+") === 0) {
$tw.boot.extraPlugins.push($tw.boot.argv[0].substring(1));
$tw.boot.argv.splice(0,1);
}
// 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

View File

@ -1,5 +1,5 @@
created: 20131219100520659 created: 20131219100520659
modified: 20180626122347768 modified: 20190412170813209
tags: [[TiddlyWiki on Node.js]] tags: [[TiddlyWiki on Node.js]]
title: Using TiddlyWiki on Node.js title: Using TiddlyWiki on Node.js
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -14,12 +14,21 @@ tiddlywiki --verbose --load mywiki.html --rendertiddler ReadMe ./readme.html
Running `tiddlywiki` from the command line boots the TiddlyWiki kernel, loads the core plugins and establishes an empty wiki store. It then sequentially processes the command line arguments from left to right. The arguments are separated with spaces. Running `tiddlywiki` from the command line boots the TiddlyWiki kernel, loads the core plugins and establishes an empty wiki store. It then sequentially processes the command line arguments from left to right. The arguments are separated with spaces.
The first argument is the optional path to the [[TiddlyWikiFolder|TiddlyWikiFolders]] to be loaded. If not present, then the current directory is used. <<.from-version "5.1.20">> First, there can be zero or more plugin references identified by the prefix `+`. These plugins are loaded in addition to any specified in the [[TiddlyWikiFolder|TiddlyWikiFolders]].
The next argument is the optional path to the [[TiddlyWikiFolder|TiddlyWikiFolders]] to be loaded. If not present, then the current directory is used.
The commands and their individual arguments follow, each command being identified by the prefix `--`. The commands and their individual arguments follow, each command being identified by the prefix `--`.
``` ```
tiddlywiki [<wikipath>] [--<command> [<arg>[,<arg>]]] tiddlywiki [+<pluginname>] [<wikipath>] [--<command> [<arg>[,<arg>]]]
```
For example:
```
tiddlywiki --version
tiddlywiki +plugins/tiddlywiki/filesystem +plugins/tiddlywiki/tiddlyweb mywiki --listen
``` ```
<<.from-version "5.1.18">> Commands such as the ListenCommand that support large numbers of parameters can use NamedCommandParameters to make things less unwieldy. For example: <<.from-version "5.1.18">> Commands such as the ListenCommand that support large numbers of parameters can use NamedCommandParameters to make things less unwieldy. For example: