Update a single-file TiddlyWiki from the command line

Here’s a Windows command line that can update a single file wiki in place. Note you need to have the latest tiddlywiki command installed via nodejs, and updated to the latest version.

As usual, backup your wiki before performing this operation.

> tiddlywiki --load "mywiki.html" --output . --render  "$:/core/save/all" "mywiki.html" "text/plain"

Of course, you can turn this into a batch file easily enough:

copy "%1" "%1"-%RANDOM%
tiddlywiki --load "%1" --output . --render  "$:/core/save/all" "%1" "text/plain"

And using the batch file (named twup.cmd)

> twup mywiki.html

That’s it. I prefer this to using the online upgrade which feels clumsy to me.

2 Likes

Makes me wonder if a upgrade Command would be a useful addition?

Thanks for the command, I didn’t know you could do that.

I’m not sure rendering straight to the source file will always work. I mean, it probably works for you, right now, in the happy flow. But if the implementation of the tiddlywiki command changes, or you get some strange disk or privilege exception, you could end up with an empty file.

It would probably be safer to render to another file, check if tiddlywiki was successful, and then rename the new file. Maybe something like this for Powershell:

param($twFile)

tiddlywiki --load $twFile --output . --render  '$:/core/save/all' "$twFile.new" 'text/plain'
if ($?) {
    // tiddlywiki was successful
    Move-Item -Force $twFile "$twFile.bak"
    Move-Item -Force "$twFile.new" $twFile
}

You can also build a single-file wiki using the command line from several sources with the –load command.

Let’s say you want to build a wiki from a ,html and a .json file.

tw --load "empty.html" --load "tiddlers.json" --output "." --render "$$:/core/save/all" "main.html" "text/plain"

Also, --load will accept a folder of tiddlers. Nice way to automate wiki building if you like single-file as opposed to node, but still want separate files for tiddlers for development. Which lends itself to automated building using tools like make, and building various versions such as 'develandrelease`, for example.

  • Note the double $$ - it’s a Windows thing.