mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-12-31 12:39:03 +00:00
* Move Node.js specific files out of the core plugin * Package server files as new $:/core-server plugin * Missed commander.js * Fix crash in browser * Extend server-only mechanism to be usable by other plugins * in * Revert "Extend server-only mechanism to be usable by other plugins" This reverts commit3faf503073. * Revert "in" This reverts commitb80213128f. * Reapply "Extend server-only mechanism to be usable by other plugins" This reverts commitc6c83bc18b. * Fix test failure * Move filesystem utilities into core-server * Move old-style release notes out of the way * Move the 5.4.0 release note into the right place * Revert "Move the 5.4.0 release note into the right place" This reverts commit3f5c2bfba3. * Revert "Move old-style release notes out of the way" This reverts commitee16e48a43.
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
/*\
|
|
title: $:/core/modules/commands/import.js
|
|
type: application/javascript
|
|
module-type: command
|
|
|
|
Command to import tiddlers from a file
|
|
|
|
\*/
|
|
|
|
"use strict";
|
|
|
|
exports.info = {
|
|
name: "import",
|
|
synchronous: true
|
|
};
|
|
|
|
var Command = function(params,commander,callback) {
|
|
this.params = params;
|
|
this.commander = commander;
|
|
this.callback = callback;
|
|
};
|
|
|
|
Command.prototype.execute = function() {
|
|
var self = this,
|
|
fs = require("fs"),
|
|
path = require("path");
|
|
if(this.params.length < 2) {
|
|
return "Missing parameters";
|
|
}
|
|
var filename = self.params[0],
|
|
deserializer = self.params[1],
|
|
title = self.params[2] || filename,
|
|
encoding = self.params[3] || "utf8",
|
|
text = fs.readFileSync(filename,encoding),
|
|
tiddlers = this.commander.wiki.deserializeTiddlers(null,text,{title: title},{deserializer: deserializer});
|
|
$tw.utils.each(tiddlers,function(tiddler) {
|
|
self.commander.wiki.importTiddler(new $tw.Tiddler(tiddler));
|
|
});
|
|
this.commander.log(tiddlers.length + " tiddler(s) imported");
|
|
return null;
|
|
};
|
|
|
|
exports.Command = Command;
|