From dc8871f9a2beeb8df70b6c264241637507265475 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 7 Dec 2011 17:26:50 +0000 Subject: [PATCH] Added command line switch to load tiddlers --- readme.md | 4 +--- tiddlywiki.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 0591de5f6..0331f4a4e 100644 --- a/readme.md +++ b/readme.md @@ -38,12 +38,10 @@ As of 2nd December 2011, cook.js can now build a fully functional TiddlyWiki fro ## Plans for new command line interface -The idea is to join `cook.js`, `ginsu.js` and `server.js` into a single command line tool, provisionally called `tiddlywiki.js`. This would be used as follows: +There is now an experimental new command line interface that combines `cook.js`, `ginsu.js` and `server.js`, provisionally called `tiddlywiki.js`. It is used as follows: node tiddlywiki.js -An interesting potential goal is that the same `tiddlywiki.js` file could be used in the browser as on the server side. - The command line options are processed in sequential order from left to right. Processing pauses during long operations, like loading a recipe file and all the subrecipes and tiddlers that it references. The following options are available: --recipe # Loads a specfied `.recipe` file diff --git a/tiddlywiki.js b/tiddlywiki.js index 322ebec7d..be2e018c3 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -11,6 +11,7 @@ var WikiStore = require("./js/WikiStore.js").WikiStore, Tiddler = require("./js/Tiddler.js").Tiddler, tiddlyWikiInput = require("./js/TiddlyWikiInput.js"), tiddlerOutput = require("./js/TiddlerOutput.js"), + tiddlerInput = require("./js/TiddlerInput.js"), util = require("util"), fs = require("fs"), path = require("path"), @@ -86,10 +87,28 @@ var commandLineSwitches = { } } }, + dumpstore: { + args: {min: 0, max: 0}, + handler: function(args,callback) { + console.log("Store is:\n%s",util.inspect(store,false,10)); + process.nextTick(function() {callback(null);}); + } + }, load: { args: {min: 1, max: 1}, handler: function(args,callback) { - process.nextTick(function() {callback(null);}); + fs.readFile(args[0],"utf8",function(err,data) { + if(err) { + callback(err); + } else { + var fields = {title: args[0]}; + var tiddlers = tiddlerInput.parseTiddlerFile(data,path.extname(args[0]),fields); + for(var t=0; t