Skip to content

Commit

Permalink
the rewrite of everything
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen22 committed Jan 9, 2025
1 parent 48e56fa commit 14c7c36
Show file tree
Hide file tree
Showing 58 changed files with 2,305 additions and 2,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;

if(this.params.length < 2) {
Expand All @@ -37,7 +37,7 @@ Command.prototype.execute = function() {
var permission_name = this.params[0];
var description = this.params[1];

$tw.mws.store.sqlTiddlerDatabase.createPermission(permission_name, description);
await $tw.mws.store.sqlTiddlerDatabase.createPermission(permission_name, description);
self.callback();
return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;

if(this.params.length < 2) {
Expand All @@ -37,7 +37,7 @@ Command.prototype.execute = function() {
var role_name = this.params[0];
var description = this.params[1];

$tw.mws.store.sqlTiddlerDatabase.createRole(role_name, description);
await $tw.mws.store.sqlTiddlerDatabase.createRole(role_name, description);
self.callback(null, "Role Created Successfully!");
return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;

if(this.params.length < 2) {
Expand All @@ -41,10 +41,10 @@ Command.prototype.execute = function() {
var email = this.params[2] || username + "@example.com";
var hashedPassword = crypto.createHash("sha256").update(password).digest("hex");

var user = $tw.mws.store.sqlTiddlerDatabase.getUserByUsername(username);
var user = await $tw.mws.store.sqlTiddlerDatabase.getUserByUsername(username);

if(!user) {
$tw.mws.store.sqlTiddlerDatabase.createUser(username, email, hashedPassword);
await $tw.mws.store.sqlTiddlerDatabase.createUser(username, email, hashedPassword);
console.log("User Account Created Successfully with username: " + username + " and password: " + password);
self.callback();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;

if(this.params.length < 2) {
Expand All @@ -36,8 +36,8 @@ Command.prototype.execute = function() {

var role_name = this.params[0];
var permission_name = this.params[1];
var role = $tw.mws.store.sqlTiddlerDatabase.getRoleByName(role_name);
var permission = $tw.mws.store.sqlTiddlerDatabase.getPermissionByName(permission_name);
var role = await $tw.mws.store.sqlTiddlerDatabase.getRoleByName(role_name);
var permission = await $tw.mws.store.sqlTiddlerDatabase.getPermissionByName(permission_name);

if(!role) {
return "Error: Unable to find Role: "+role_name;
Expand All @@ -47,10 +47,10 @@ Command.prototype.execute = function() {
return "Error: Unable to find Permission: "+permission_name;
}

var permission = $tw.mws.store.sqlTiddlerDatabase.getPermissionByName(permission_name);
var permission = await $tw.mws.store.sqlTiddlerDatabase.getPermissionByName(permission_name);


$tw.mws.store.sqlTiddlerDatabase.addPermissionToRole(role.role_id, permission.permission_id);
await $tw.mws.store.sqlTiddlerDatabase.addPermissionToRole(role.role_id, permission.permission_id);
self.callback();
return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;

if(this.params.length < 2) {
Expand All @@ -36,8 +36,8 @@ Command.prototype.execute = function() {

var username = this.params[0];
var role_name = this.params[1];
var role = $tw.mws.store.sqlTiddlerDatabase.getRoleByName(role_name);
var user = $tw.mws.store.sqlTiddlerDatabase.getUserByUsername(username);
var role = await $tw.mws.store.sqlTiddlerDatabase.getRoleByName(role_name);
var user = await $tw.mws.store.sqlTiddlerDatabase.getUserByUsername(username);

if(!role) {
return "Error: Unable to find Role: "+role_name;
Expand All @@ -47,7 +47,7 @@ Command.prototype.execute = function() {
return "Error: Unable to find user with the username "+username;
}

$tw.mws.store.sqlTiddlerDatabase.addRoleToUser(user.user_id, role.role_id);
await $tw.mws.store.sqlTiddlerDatabase.addRoleToUser(user.user_id, role.role_id);

console.log(role_name+" role has been assigned to user with username "+username)
self.callback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;
// Check parameters
if(this.params.length < 1) {
Expand All @@ -34,7 +34,7 @@ Command.prototype.execute = function() {
var bagName = this.params[0],
bagDescription = this.params[1] || bagName;
// Create bag
var result = $tw.mws.store.createBag(bagName,bagDescription);
var result = await $tw.mws.store.createBag(bagName,bagDescription);
if(result) {
return result.message;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;
// Check parameters
if(this.params.length < 1) {
return "Missing recipe name";
}
var recipeName = this.params[0],
bagList = (this.params[1] || "").split(" "),
recipeDescription = this.params[2] || recipeNameName;
recipeDescription = this.params[2];
// Create recipe
var result = $tw.mws.store.createRecipe(recipeName,bagList,recipeDescription);
var result = await $tw.mws.store.createRecipe(recipeName,bagList,recipeDescription);
if(result) {
return result.message;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Command to load archive of recipes, bags and tiddlers from a directory

exports.info = {
name: "mws-load-archive",
synchronous: true
synchronous: false
};

var Command = function(params,commander,callback) {
Expand All @@ -23,18 +23,18 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
var self = this;
Command.prototype.execute = async function() {
// Check parameters
if(this.params.length < 1) {
return "Missing pathname";
}
var archivePath = this.params[0];
loadBackupArchive(archivePath);
await loadBackupArchive(archivePath);
this.callback();
return null;
};

function loadBackupArchive(archivePath) {
async function loadBackupArchive(archivePath) {
const fs = require("fs"),
path = require("path");
// Iterate the bags
Expand All @@ -43,7 +43,7 @@ function loadBackupArchive(archivePath) {
const bagName = decodeURIComponent(bagFilename);
console.log(`Reading bag ${bagName}`);
const bagInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"bags",bagFilename,"meta.json"),"utf8"));
$tw.mws.store.createBag(bagName,bagInfo.description,bagInfo.accesscontrol);
await $tw.mws.store.createBag(bagName,bagInfo.description,bagInfo.accesscontrol);
if(fs.existsSync(path.resolve(archivePath,"bags",bagFilename,"tiddlers"))) {
const tiddlerFilenames = fs.readdirSync(path.resolve(archivePath,"bags",bagFilename,"tiddlers"));
for(const tiddlerFilename of tiddlerFilenames) {
Expand All @@ -52,7 +52,7 @@ function loadBackupArchive(archivePath) {
jsonTiddler = fs.readFileSync(tiddlerPath,"utf8"),
tiddler = sanitiseTiddler(JSON.parse(jsonTiddler));
if(tiddler && tiddler.title) {
$tw.mws.store.saveBagTiddler(tiddler,bagName);
await $tw.mws.store.saveBagTiddler(tiddler,bagName);
} else {
console.log(`Malformed JSON tiddler in file ${tiddlerPath}`);
}
Expand All @@ -66,7 +66,7 @@ function loadBackupArchive(archivePath) {
if(recipeFilename.endsWith(".json")) {
const recipeName = decodeURIComponent(recipeFilename.substring(0,recipeFilename.length - ".json".length));
const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"recipes",recipeFilename),"utf8"));
$tw.mws.store.createRecipe(recipeName,jsonInfo.bag_names,jsonInfo.description,jsonInfo.accesscontrol);
await $tw.mws.store.createRecipe(recipeName,jsonInfo.bag_names,jsonInfo.description,jsonInfo.accesscontrol);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,71 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
var self = this;
loadPluginBags();
Command.prototype.execute = async function() {
await loadPluginBags();
return null;
};

function loadPluginBags() {
async function loadPluginBags() {
const path = require("path"),
fs = require("fs");
// Copy plugins
var makePluginBagName = function(type,publisher,name) {
return "$:/" + type + "/" + (publisher ? publisher + "/" : "") + name;
},
savePlugin = function(pluginFields,type,publisher,name) {
savePlugin = async function(pluginFields,type,publisher,name) {
const bagName = makePluginBagName(type,publisher,name);
const result = $tw.mws.store.createBag(bagName,pluginFields.description || "(no description)",{allowPrivilegedCharacters: true});
const result = await $tw.mws.store.createBag(bagName,pluginFields.description || "(no description)",{allowPrivilegedCharacters: true});
if(result) {
console.log(`Error creating plugin bag ${bagname}: ${JSON.stringify(result)}`);
console.log(`Error creating plugin bag ${bagName}: ${JSON.stringify(result)}`);
}
$tw.mws.store.saveBagTiddler(pluginFields,bagName);
await $tw.mws.store.saveBagTiddler(pluginFields,bagName);
},
collectPlugins = function(folder,type,publisher) {
collectPlugins = async function(folder,type,publisher) {
var pluginFolders = $tw.utils.getSubdirectories(folder) || [];
for(var p=0; p<pluginFolders.length; p++) {
const pluginFolderName = pluginFolders[p];
if(!$tw.boot.excludeRegExp.test(pluginFolderName)) {
var pluginFields = $tw.loadPluginFolder(path.resolve(folder,pluginFolderName));
if(pluginFields && pluginFields.title) {
savePlugin(pluginFields,type,publisher,pluginFolderName);
await savePlugin(pluginFields,type,publisher,pluginFolderName);
}
}
}
},
collectPublisherPlugins = function(folder,type) {
collectPublisherPlugins = async function(folder,type) {
var publisherFolders = $tw.utils.getSubdirectories(folder) || [];
for(var t=0; t<publisherFolders.length; t++) {
const publisherFolderName = publisherFolders[t];
if(!$tw.boot.excludeRegExp.test(publisherFolderName)) {
collectPlugins(path.resolve(folder,publisherFolderName),type,publisherFolderName);
await collectPlugins(path.resolve(folder,publisherFolderName),type,publisherFolderName);
}
}
};

const publisherPlugins = [];
const languagePlugins = [];

$tw.utils.each($tw.getLibraryItemSearchPaths($tw.config.pluginsPath,$tw.config.pluginsEnvVar),function(folder) {
collectPublisherPlugins(folder,"plugins");
publisherPlugins.push([folder,"plugins"]);
// collectPublisherPlugins(folder,"plugins");
});
$tw.utils.each($tw.getLibraryItemSearchPaths($tw.config.themesPath,$tw.config.themesEnvVar),function(folder) {
collectPublisherPlugins(folder,"themes");
publisherPlugins.push([folder,"themes"]);
// collectPublisherPlugins(folder,"themes");
});
$tw.utils.each($tw.getLibraryItemSearchPaths($tw.config.languagesPath,$tw.config.languagesEnvVar),function(folder) {
collectPlugins(folder,"languages");
languagePlugins.push([folder,"languages"]);
// collectPlugins(folder,"languages");
});

for(const[folder,type] of publisherPlugins) {
await collectPublisherPlugins(folder,type);
}

for(const[folder,type] of languagePlugins) {
await collectPlugins(folder,type);
}
}

exports.Command = Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;
// Check parameters
if(this.params.length < 2) {
return "Missing pathname and/or bag name";
}
var tiddlersPath = this.params[0],
bagName = this.params[1];
$tw.mws.store.saveTiddlersFromPath(tiddlersPath,bagName);
await $tw.mws.store.saveTiddlersFromPath(tiddlersPath,bagName);
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ var Command = function(params,commander,callback) {
this.callback = callback;
};

Command.prototype.execute = function() {
Command.prototype.execute = async function() {
var self = this;
// Check parameters
if(this.params.length < 5) {
return "Missing parameters for --mws-load-wiki-folder command";
}
var archivePath = this.params[0];
loadWikiFolder({
await loadWikiFolder({
wikiPath: this.params[0],
bagName: this.params[1],
bagDescription: this.params[2],
Expand All @@ -48,7 +48,7 @@ function makePluginBagName(type,publisher,name) {
}

// Copy TiddlyWiki core editions
function loadWikiFolder(options) {
async function loadWikiFolder(options) {
const path = require("path"),
fs = require("fs");
// Read the tiddlywiki.info file
Expand All @@ -59,7 +59,7 @@ function loadWikiFolder(options) {
}
if(wikiInfo) {
// Create the bag
const result = $tw.mws.store.createBag(options.bagName,options.bagDescription);
const result = await $tw.mws.store.createBag(options.bagName,options.bagDescription);
if(result) {
console.log(`Error creating bag ${options.bagName} for edition ${options.wikiPath}: ${JSON.stringify(result)}`);
}
Expand All @@ -83,8 +83,8 @@ function loadWikiFolder(options) {
processPlugins("languages",wikiInfo.languages);
// Create the recipe
recipeList.push(options.bagName);
$tw.mws.store.createRecipe(options.recipeName,recipeList,options.recipeDescription);
$tw.mws.store.saveTiddlersFromPath(path.resolve(options.wikiPath,$tw.config.wikiTiddlersSubDir),options.bagName);
await $tw.mws.store.createRecipe(options.recipeName,recipeList,options.recipeDescription);
await $tw.mws.store.saveTiddlersFromPath(path.resolve(options.wikiPath,$tw.config.wikiTiddlersSubDir),options.bagName);
}
}

Expand Down
Loading

0 comments on commit 14c7c36

Please sign in to comment.