UNPKG

tiddlywiki-production

Version:
1 lines 5.03 kB
$tw.preloadTiddler({"title":"$:/plugins/tiddlywiki/filesystem","name":"Filesystem","description":"Synchronise changes to the local filesystem","list":"readme","version":"5.1.22","plugin-type":"plugin","dependents":"","type":"application/json","text":"{\"tiddlers\":{\"$:/plugins/tiddlywiki/filesystem/filesystemadaptor.js\":{\"title\":\"$:/plugins/tiddlywiki/filesystem/filesystemadaptor.js\",\"text\":\"/*\\\\\\ntitle: $:/plugins/tiddlywiki/filesystem/filesystemadaptor.js\\ntype: application/javascript\\nmodule-type: syncadaptor\\n\\nA sync adaptor module for synchronising with the local filesystem via node.js APIs\\n\\n\\\\*/\\n(function(){\\n\\n/*jslint node: true, browser: true */\\n/*global $tw: false */\\n\\\"use strict\\\";\\n\\n// Get a reference to the file system\\nvar fs = $tw.node ? require(\\\"fs\\\") : null,\\n\\tpath = $tw.node ? require(\\\"path\\\") : null;\\n\\nfunction FileSystemAdaptor(options) {\\n\\tvar self = this;\\n\\tthis.wiki = options.wiki;\\n\\tthis.logger = new $tw.utils.Logger(\\\"filesystem\\\",{colour: \\\"blue\\\"});\\n\\t// Create the <wiki>/tiddlers folder if it doesn't exist\\n\\t$tw.utils.createDirectory($tw.boot.wikiTiddlersPath);\\n}\\n\\nFileSystemAdaptor.prototype.name = \\\"filesystem\\\";\\n\\nFileSystemAdaptor.prototype.supportsLazyLoading = false;\\n\\nFileSystemAdaptor.prototype.isReady = function() {\\n\\t// The file system adaptor is always ready\\n\\treturn true;\\n};\\n\\nFileSystemAdaptor.prototype.getTiddlerInfo = function(tiddler) {\\n\\treturn {};\\n};\\n\\n/*\\nReturn a fileInfo object for a tiddler, creating it if necessary:\\n filepath: the absolute path to the file containing the tiddler\\n type: the type of the tiddler file (NOT the type of the tiddler -- see below)\\n hasMetaFile: true if the file also has a companion .meta file\\n\\nThe boot process populates $tw.boot.files for each of the tiddler files that it loads. The type is found by looking up the extension in $tw.config.fileExtensionInfo (eg \\\"application/x-tiddler\\\" for \\\".tid\\\" files).\\n\\nIt is the responsibility of the filesystem adaptor to update $tw.boot.files for new files that are created.\\n*/\\nFileSystemAdaptor.prototype.getTiddlerFileInfo = function(tiddler,callback) {\\n\\t// See if we've already got information about this file\\n\\tvar title = tiddler.fields.title,\\n\\t\\tfileInfo = $tw.boot.files[title];\\n\\tif(!fileInfo) {\\n\\t\\t// Otherwise, we'll need to generate it\\n\\t\\tfileInfo = $tw.utils.generateTiddlerFileInfo(tiddler,{\\n\\t\\t\\tdirectory: $tw.boot.wikiTiddlersPath,\\n\\t\\t\\tpathFilters: this.wiki.getTiddlerText(\\\"$:/config/FileSystemPaths\\\",\\\"\\\").split(\\\"\\\\n\\\"),\\n\\t\\t\\twiki: this.wiki\\n\\t\\t});\\n\\t\\t$tw.boot.files[title] = fileInfo;\\n\\t}\\n\\tcallback(null,fileInfo);\\n};\\n\\n\\n/*\\nSave a tiddler and invoke the callback with (err,adaptorInfo,revision)\\n*/\\nFileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback) {\\n\\tvar self = this;\\n\\tthis.getTiddlerFileInfo(tiddler,function(err,fileInfo) {\\n\\t\\tif(err) {\\n\\t\\t\\treturn callback(err);\\n\\t\\t}\\n\\t\\t$tw.utils.saveTiddlerToFile(tiddler,fileInfo,callback);\\n\\t});\\n};\\n\\n/*\\nLoad a tiddler and invoke the callback with (err,tiddlerFields)\\n\\nWe don't need to implement loading for the file system adaptor, because all the tiddler files will have been loaded during the boot process.\\n*/\\nFileSystemAdaptor.prototype.loadTiddler = function(title,callback) {\\n\\tcallback(null,null);\\n};\\n\\n/*\\nDelete a tiddler and invoke the callback with (err)\\n*/\\nFileSystemAdaptor.prototype.deleteTiddler = function(title,callback,options) {\\n\\tvar self = this,\\n\\t\\tfileInfo = $tw.boot.files[title];\\n\\t// Only delete the tiddler if we have writable information for the file\\n\\tif(fileInfo) {\\n\\t\\t// Delete the file\\n\\t\\tfs.unlink(fileInfo.filepath,function(err) {\\n\\t\\t\\tif(err) {\\n\\t\\t\\t\\treturn callback(err);\\n\\t\\t\\t}\\n\\t\\t\\t// Delete the metafile if present\\n\\t\\t\\tif(fileInfo.hasMetaFile) {\\n\\t\\t\\t\\tfs.unlink(fileInfo.filepath + \\\".meta\\\",function(err) {\\n\\t\\t\\t\\t\\tif(err) {\\n\\t\\t\\t\\t\\t\\treturn callback(err);\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\treturn $tw.utils.deleteEmptyDirs(path.dirname(fileInfo.filepath),callback);\\n\\t\\t\\t\\t});\\n\\t\\t\\t} else {\\n\\t\\t\\t\\treturn $tw.utils.deleteEmptyDirs(path.dirname(fileInfo.filepath),callback);\\n\\t\\t\\t}\\n\\t\\t});\\n\\t} else {\\n\\t\\tcallback(null);\\n\\t}\\n};\\n\\nif(fs) {\\n\\texports.adaptorClass = FileSystemAdaptor;\\n}\\n\\n})();\\n\",\"type\":\"application/javascript\",\"module-type\":\"syncadaptor\"},\"$:/plugins/tiddlywiki/filesystem/readme\":{\"title\":\"$:/plugins/tiddlywiki/filesystem/readme\",\"text\":\"The filesystem plugin is used under Node.js to synchronise tiddler changes back to the file system. It is inert when used in the browser.\\n\\n[[Source code|https://github.com/Jermolene/TiddlyWiki5/blob/master/plugins/tiddlywiki/filesystem]]\\n\"}}}"});