1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-29 14:13:18 +00:00
TiddlyWiki5/core/modules/utils/pluginmaker.js
Mario Pietsch 8aa558eb2c
Remove module function wrapper and add matching configurations for dprint and eslint (#7596)
* remove blks first try

* dprint.json seems to be OK, some forgotten functions

* add some more space-after-keyword settings

* server remove blks

* add **/files to dprint exclude

* dprint.js fixes a typo

* add boot.js and bootprefix.js to dprint exclude

* dprint change dprint.json

* add dprint fmt as script

* remove jslint comments

* fix whitespace

* fix whitespace

* remove function-wrapper from geospatial plugin

* fix whitespace

* add function wrapper to dyannotate-startup

* remove dpring.json
2025-03-21 17:22:57 +00:00

75 lines
2.3 KiB
JavaScript

/*\
title: $:/core/modules/utils/pluginmaker.js
type: application/javascript
module-type: utils
A quick and dirty way to pack up plugins within the browser.
\*/
"use strict";
/*
Repack a plugin, and then delete any non-shadow payload tiddlers
*/
exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
additionalTiddlers = additionalTiddlers || [];
excludeTiddlers = excludeTiddlers || [];
// Get the plugin tiddler
var pluginTiddler = $tw.wiki.getTiddler(title);
if(!pluginTiddler) {
throw "No such tiddler as " + title;
}
// Extract the JSON
var jsonPluginTiddler = $tw.utils.parseJSONSafe(pluginTiddler.fields.text,null);
if(!jsonPluginTiddler) {
throw "Cannot parse plugin tiddler " + title + "\n" + $tw.language.getString("Error/Caption") + ": " + e;
}
// Get the list of tiddlers
var tiddlers = Object.keys(jsonPluginTiddler.tiddlers);
// Add the additional tiddlers
$tw.utils.pushTop(tiddlers,additionalTiddlers);
// Remove any excluded tiddlers
for(var t=tiddlers.length-1; t>=0; t--) {
if(excludeTiddlers.indexOf(tiddlers[t]) !== -1) {
tiddlers.splice(t,1);
}
}
// Pack up the tiddlers into a block of JSON
var plugins = {};
$tw.utils.each(tiddlers,function(title) {
var tiddler = $tw.wiki.getTiddler(title),
fields = {};
$tw.utils.each(tiddler.fields,function (value,name) {
fields[name] = tiddler.getFieldString(name);
});
plugins[title] = fields;
});
// Retrieve and bump the version number
var pluginVersion = $tw.utils.parseVersion(pluginTiddler.getFieldString("version") || "0.0.0") || {
major: "0",
minor: "0",
patch: "0"
};
pluginVersion.patch++;
var version = pluginVersion.major + "." + pluginVersion.minor + "." + pluginVersion.patch;
if(pluginVersion.prerelease) {
version += "-" + pluginVersion.prerelease;
}
if(pluginVersion.build) {
version += "+" + pluginVersion.build;
}
// Save the tiddler
$tw.wiki.addTiddler(new $tw.Tiddler(pluginTiddler,{text: JSON.stringify({tiddlers: plugins},null,4), version: version}));
// Delete any non-shadow constituent tiddlers
$tw.utils.each(tiddlers,function(title) {
if($tw.wiki.tiddlerExists(title)) {
$tw.wiki.deleteTiddler(title);
}
});
// Trigger an autosave
$tw.rootWidget.dispatchEvent({type: "tm-auto-save-wiki"});
// Return a heartwarming confirmation
return "Plugin " + title + " successfully saved";
};