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

Initial commit

This commit adds support for dynamic tokens within build commands. See the tiddlywiki.info file. Also adds an echo command to make debugging easier.

I also intend to add a node type for prompting the user for a string.
This commit is contained in:
Jeremy Ruston 2024-10-19 12:26:11 +01:00
parent e259f414d9
commit 50118dbe13
3 changed files with 142 additions and 47 deletions

View File

@ -64,26 +64,78 @@ Commander.prototype.execute = function() {
this.executeNextCommand(); this.executeNextCommand();
}; };
/*
Returns the next string token without consuming it, or null if there are none left
*/
Commander.prototype.peekNextToken = function() {
if(this.nextToken >= this.commandTokens.length) {
return null;
} else {
return this.stringifyToken(this.nextToken);
}
};
/*
Returns and consumes the next string token, or null if there are none left
*/
Commander.prototype.getNextToken = function() {
if(this.nextToken >= this.commandTokens.length) {
return null;
} else {
return this.stringifyToken(this.nextToken++);
}
};
/*
Returns a specified stringified token, or null if the index does not exist
*/
Commander.prototype.stringifyToken = function(index) {
if(index >= this.commandTokens.length) {
return null;
} else {
var token = this.commandTokens[index];
if(typeof token === "string") {
return token;
} else if(typeof token === "object") {
switch(token.type) {
case "filter":
return this.wiki.filterTiddlers(token.text)[0] || "";
break;
case "wikified":
return this.wiki.renderText("text/plain","text/vnd.tiddlywiki",token.text,{
parseAsInline: false,
parentWidget: $tw.rootWidget
});
break;
default:
throw "Unknown dynamic command token type: " + token.type;
break;
}
}
}
};
/* /*
Execute the next command in the sequence Execute the next command in the sequence
*/ */
Commander.prototype.executeNextCommand = function() { Commander.prototype.executeNextCommand = function() {
var self = this; var self = this;
// Invoke the callback if there are no more commands
if(this.nextToken >= this.commandTokens.length) {
this.callback(null);
} else {
// Get and check the command token // Get and check the command token
var commandName = this.commandTokens[this.nextToken++]; var commandName = this.getNextToken();
if(!commandName) {
return this.callback(null);
}
if(commandName.substr(0,2) !== "--") { if(commandName.substr(0,2) !== "--") {
this.callback("Missing command: " + commandName); this.callback("Missing command: " + commandName);
} else { } else {
commandName = commandName.substr(2); // Trim off the -- commandName = commandName.substr(2); // Trim off the --
// Accumulate the parameters to the command // Accumulate the parameters to the command
var params = []; var params = [],
while(this.nextToken < this.commandTokens.length && nextToken = this.peekNextToken();
this.commandTokens[this.nextToken].substr(0,2) !== "--") { while(typeof nextToken === "string" && nextToken.substr(0,2) !== "--") {
params.push(this.commandTokens[this.nextToken++]); params.push(this.getNextToken());
nextToken = this.peekNextToken();
} }
// Get the command info // Get the command info
var command = $tw.commands[commandName], var command = $tw.commands[commandName],
@ -126,7 +178,6 @@ Commander.prototype.executeNextCommand = function() {
} }
} }
} }
}
}; };
/* /*

View File

@ -0,0 +1,32 @@
/*\
title: $:/core/modules/commands/echo.js
type: application/javascript
module-type: command
Command to echo input parameters
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.info = {
name: "echo",
synchronous: true
};
var Command = function(params,commander) {
this.params = params;
this.commander = commander;
};
Command.prototype.execute = function() {
this.commander.streams.output.write(JSON.stringify(this.params,null,4) + "\n");
return null;
};
exports.Command = Command;
})();

View File

@ -23,6 +23,18 @@
"languages": [ "languages": [
], ],
"build": { "build": {
"dynamic": [
"--echo","testing",
{
"type": "wikified",
"text": "<<version>>-prod.html"
},
"thingy",
{
"type": "filter",
"text": "[<version>!match[5.3.6-prerelease]then[text/html]else[text/plain]]"
}
],
"index": [ "index": [
"--savetiddlers","[tag[external-image]]","images", "--savetiddlers","[tag[external-image]]","images",
"--render","[tag[external-text]]","[encodeuricomponent[]addprefix[text/]addsuffix[.tid]]","text/plain","$:/core/templates/tid-tiddler", "--render","[tag[external-text]]","[encodeuricomponent[]addprefix[text/]addsuffix[.tid]]","text/plain","$:/core/templates/tid-tiddler",