/*\ title: $:/plugins/tiddlywiki/multiwikiserver/startup.js type: application/javascript module-type: startup Multi wiki server initialisation \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; // Export name and synchronous status exports.name = "multiwikiserver"; exports.platforms = ["node"]; exports.before = ["story"]; exports.synchronous = true; exports.startup = function() { const store = setupStore(); loadStore(store); $tw.mws = { store: store, serverManager: new ServerManager({ store: store }) }; } function setupStore() { const path = require("path"); // Create and initialise the attachment store and the tiddler store const AttachmentStore = require("$:/plugins/tiddlywiki/multiwikiserver/store/attachments.js").AttachmentStore, attachmentStore = new AttachmentStore({ storePath: path.resolve($tw.boot.wikiPath,"store/") }), SqlTiddlerStore = require("$:/plugins/tiddlywiki/multiwikiserver/store/sql-tiddler-store.js").SqlTiddlerStore, store = new SqlTiddlerStore({ databasePath: path.resolve($tw.boot.wikiPath,"store/database.sqlite"), engine: $tw.wiki.getTiddlerText("$:/config/MultiWikiServer/Engine","better"), // better || wasm attachmentStore: attachmentStore }); return store; } function loadStore(store) { const path = require("path"), fs = require("fs"); // Performance timing console.time("mws-initial-load"); // Copy plugins var makePluginBagName = function(type,publisher,name) { return "$:/" + type + "/" + (publisher ? publisher + "/" : "") + name; }, savePlugin = function(pluginFields,type,publisher,name) { const bagName = makePluginBagName(type,publisher,name); const result = store.createBag(bagName,pluginFields.description || "(no description)",{allowPrivilegedCharacters: true}); if(result) { console.log(`Error creating plugin bag ${bagname}: ${JSON.stringify(result)}`); } console.log(`saveBagTiddler of ${pluginFields.title} to ${bagName}`); store.saveBagTiddler(pluginFields,bagName); }, collectPlugins = function(folder,type,publisher) { var pluginFolders = $tw.utils.getSubdirectories(folder) || []; for(var p=0; p