mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +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:
parent
e259f414d9
commit
50118dbe13
@ -64,26 +64,78 @@ Commander.prototype.execute = function() {
|
||||
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
|
||||
*/
|
||||
Commander.prototype.executeNextCommand = function() {
|
||||
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
|
||||
var commandName = this.commandTokens[this.nextToken++];
|
||||
var commandName = this.getNextToken();
|
||||
if(!commandName) {
|
||||
return this.callback(null);
|
||||
}
|
||||
if(commandName.substr(0,2) !== "--") {
|
||||
this.callback("Missing command: " + commandName);
|
||||
} else {
|
||||
commandName = commandName.substr(2); // Trim off the --
|
||||
// Accumulate the parameters to the command
|
||||
var params = [];
|
||||
while(this.nextToken < this.commandTokens.length &&
|
||||
this.commandTokens[this.nextToken].substr(0,2) !== "--") {
|
||||
params.push(this.commandTokens[this.nextToken++]);
|
||||
var params = [],
|
||||
nextToken = this.peekNextToken();
|
||||
while(typeof nextToken === "string" && nextToken.substr(0,2) !== "--") {
|
||||
params.push(this.getNextToken());
|
||||
nextToken = this.peekNextToken();
|
||||
}
|
||||
// Get the command info
|
||||
var command = $tw.commands[commandName],
|
||||
@ -126,7 +178,6 @@ Commander.prototype.executeNextCommand = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
32
core/modules/commands/echo.js
Normal file
32
core/modules/commands/echo.js
Normal 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;
|
||||
|
||||
})();
|
@ -23,6 +23,18 @@
|
||||
"languages": [
|
||||
],
|
||||
"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": [
|
||||
"--savetiddlers","[tag[external-image]]","images",
|
||||
"--render","[tag[external-text]]","[encodeuricomponent[]addprefix[text/]addsuffix[.tid]]","text/plain","$:/core/templates/tid-tiddler",
|
||||
|
Loading…
Reference in New Issue
Block a user