mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-05-11 03:44:06 +00:00
Save command exit with error when encountering missing tiddlers
Fixes #6603
This commit is contained in:
parent
6624ce3716
commit
73138b79aa
@ -8,46 +8,54 @@ Saves individual tiddlers in their raw text or binary format to the specified fi
|
|||||||
\*/
|
\*/
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
/*jslint node: true, browser: true */
|
||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.info = {
|
exports.info = {
|
||||||
name: "save",
|
name: "save",
|
||||||
synchronous: true
|
synchronous: true
|
||||||
};
|
};
|
||||||
|
|
||||||
var Command = function(params,commander,callback) {
|
var Command = function(params,commander,callback) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.commander = commander;
|
this.commander = commander;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
Command.prototype.execute = function() {
|
Command.prototype.execute = function() {
|
||||||
if(this.params.length < 1) {
|
if(this.params.length < 1) {
|
||||||
return "Missing filename filter";
|
return "Missing filename filter";
|
||||||
}
|
|
||||||
var self = this,
|
|
||||||
fs = require("fs"),
|
|
||||||
path = require("path"),
|
|
||||||
wiki = this.commander.wiki,
|
|
||||||
tiddlerFilter = this.params[0],
|
|
||||||
filenameFilter = this.params[1] || "[is[tiddler]]",
|
|
||||||
tiddlers = wiki.filterTiddlers(tiddlerFilter);
|
|
||||||
$tw.utils.each(tiddlers,function(title) {
|
|
||||||
var tiddler = self.commander.wiki.getTiddler(title),
|
|
||||||
type = tiddler.fields.type || "text/vnd.tiddlywiki",
|
|
||||||
contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"},
|
|
||||||
filepath = path.resolve(self.commander.outputPath,wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0]);
|
|
||||||
if(self.commander.verbose) {
|
|
||||||
console.log("Saving \"" + title + "\" to \"" + filepath + "\"");
|
|
||||||
}
|
}
|
||||||
$tw.utils.createFileDirectories(filepath);
|
var self = this,
|
||||||
fs.writeFileSync(filepath,tiddler.fields.text,contentTypeInfo.encoding);
|
fs = require("fs"),
|
||||||
});
|
path = require("path"),
|
||||||
return null;
|
result = null,
|
||||||
};
|
wiki = this.commander.wiki,
|
||||||
|
tiddlerFilter = this.params[0],
|
||||||
|
filenameFilter = this.params[1] || "[is[tiddler]]",
|
||||||
|
tiddlers = wiki.filterTiddlers(tiddlerFilter);
|
||||||
|
$tw.utils.each(tiddlers,function(title) {
|
||||||
|
if(!result) {
|
||||||
|
var tiddler = self.commander.wiki.getTiddler(title);
|
||||||
|
if(tiddler) {
|
||||||
|
var type = tiddler.fields.type || "text/vnd.tiddlywiki",
|
||||||
|
contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"},
|
||||||
|
filepath = path.resolve(self.commander.outputPath,wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0]);
|
||||||
|
if(self.commander.verbose) {
|
||||||
|
console.log("Saving \"" + title + "\" to \"" + filepath + "\"");
|
||||||
|
}
|
||||||
|
$tw.utils.createFileDirectories(filepath);
|
||||||
|
fs.writeFileSync(filepath,tiddler.fields.text,contentTypeInfo.encoding);
|
||||||
|
} else {
|
||||||
|
result = "Tiddler '" + title + "' not found";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
exports.Command = Command;
|
exports.Command = Command;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
})();
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user