2024-01-02 14:39:14 +00:00
/ * \
title : $ : / p l u g i n s / t i d d l y w i k i / m u l t i w i k i s e r v e r / i n i t . j s
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 ( ) {
2024-01-05 10:58:07 +00:00
var path = require ( "path" ) ;
2024-01-02 14:39:14 +00:00
// Install the sqlite3 global namespace
$tw . sqlite3 = {
Database : null
} ;
// Check that better-sqlite3 is installed
var logger = new $tw . utils . Logger ( "multiwikiserver" ) ;
try {
$tw . sqlite3 . Database = require ( "better-sqlite3" ) ;
} catch ( e ) {
}
if ( ! $tw . sqlite3 . Database ) {
2024-01-02 21:41:25 +00:00
logger . alert ( "The plugin 'tiddlywiki/multiwikiserver' requires the better-sqlite3 npm package to be installed. Run 'npm install' in the root of the TiddlyWiki repository" ) ;
2024-01-02 14:39:14 +00:00
return ;
}
2024-01-05 10:58:07 +00:00
// Compute the database path
var databasePath = path . resolve ( $tw . boot . wikiPath , "database.sqlite" ) ;
2024-01-02 14:39:14 +00:00
// Create and initialise the tiddler store
var SqlTiddlerStore = require ( "$:/plugins/tiddlywiki/multiwikiserver/sql-tiddler-store.js" ) . SqlTiddlerStore ;
2024-01-05 10:58:07 +00:00
$tw . sqlTiddlerStore = new SqlTiddlerStore ( {
databasePath : databasePath
} ) ;
2024-01-23 16:53:12 +00:00
// Create docs bag and recipe
2024-01-24 22:24:24 +00:00
$tw . sqlTiddlerStore . createBag ( "docs" , "TiddlyWiki Documentation from https://tiddlywiki.com/" ) ;
2024-01-23 16:53:12 +00:00
$tw . sqlTiddlerStore . createRecipe ( "docs" , [ "docs" ] , "TiddlyWiki Documentation from https://tiddlywiki.com/" ) ;
$tw . sqlTiddlerStore . saveTiddlersFromPath ( path . resolve ( $tw . boot . corePath , $tw . config . editionsPath , "tw5.com/tiddlers" ) , "docs" ) ;
2024-01-24 22:24:24 +00:00
$tw . sqlTiddlerStore . createBag ( "dev-docs" , "TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/" ) ;
2024-01-23 16:53:12 +00:00
$tw . sqlTiddlerStore . createRecipe ( "dev-docs" , [ "dev-docs" ] , "TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/" ) ;
$tw . sqlTiddlerStore . saveTiddlersFromPath ( path . resolve ( $tw . boot . corePath , $tw . config . editionsPath , "dev/tiddlers" ) , "dev-docs" ) ;
2024-01-02 14:39:14 +00:00
// Create bags and recipes
2024-01-24 22:24:24 +00:00
$tw . sqlTiddlerStore . createBag ( "bag-alpha" , "A test bag" ) ;
$tw . sqlTiddlerStore . createBag ( "bag-beta" , "Another test bag" ) ;
$tw . sqlTiddlerStore . createBag ( "bag-gamma" , "A further test bag" ) ;
2024-01-23 14:29:50 +00:00
$tw . sqlTiddlerStore . createRecipe ( "recipe-rho" , [ "bag-alpha" , "bag-beta" ] , "First wiki" ) ;
$tw . sqlTiddlerStore . createRecipe ( "recipe-sigma" , [ "bag-alpha" , "bag-gamma" ] , "Second Wiki" ) ;
$tw . sqlTiddlerStore . createRecipe ( "recipe-tau" , [ "bag-alpha" ] , "Third Wiki" ) ;
$tw . sqlTiddlerStore . createRecipe ( "recipe-upsilon" , [ "bag-alpha" , "bag-gamma" , "bag-beta" ] , "Fourth Wiki" ) ;
2024-01-02 14:39:14 +00:00
// Save tiddlers
2024-01-19 19:52:57 +00:00
$tw . sqlTiddlerStore . saveBagTiddler ( { title : "$:/SiteTitle" , text : "Bag Alpha" } , "bag-alpha" ) ;
$tw . sqlTiddlerStore . saveBagTiddler ( { title : "$:/SiteTitle" , text : "Bag Beta" } , "bag-beta" ) ;
$tw . sqlTiddlerStore . saveBagTiddler ( { title : "$:/SiteTitle" , text : "Bag Gamma" } , "bag-gamma" ) ;
2024-01-02 14:39:14 +00:00
} ;
} ) ( ) ;