1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-24 22:33:16 +00:00

Reuse $tw.loadTiddlersFromPath() in --load command

Thus allowing things like tiddlywiki.files to be used with the —load
command
This commit is contained in:
Jermolene 2016-12-14 09:54:50 +00:00
parent ad9769451d
commit 1bba9dc315

View File

@ -30,24 +30,21 @@ Command.prototype.execute = function() {
if(this.params.length < 1) { if(this.params.length < 1) {
return "Missing filename"; return "Missing filename";
} }
var ext = path.extname(self.params[0]); var ext = path.extname(self.params[0]),
fs.readFile(this.params[0],$tw.utils.getTypeEncoding(ext),function(err,data) { stat = fs.statSync(self.params[0]),
if (err) { tiddlers = $tw.loadTiddlersFromPath(self.params[0]),
self.callback(err); count = 0;
} else { $tw.utils.each(tiddlers,function(tiddlerInfo) {
var fields = {title: self.params[0]}, $tw.utils.each(tiddlerInfo.tiddlers,function(tiddler) {
type = path.extname(self.params[0]); self.commander.wiki.importTiddler(new $tw.Tiddler(tiddler));
var tiddlers = self.commander.wiki.deserializeTiddlers(type,data,fields); count++;
if(!tiddlers) { });
self.callback("No tiddlers found in file \"" + self.params[0] + "\"");
} else {
for(var t=0; t<tiddlers.length; t++) {
self.commander.wiki.importTiddler(new $tw.Tiddler(tiddlers[t]));
}
self.callback(null);
}
}
}); });
if(!count) {
self.callback("No tiddlers found in file \"" + self.params[0] + "\"");
} else {
self.callback(null);
}
return null; return null;
}; };