split all operators

This commit is contained in:
Felix Kaspar
2024-07-13 23:02:46 +02:00
parent 335a879e81
commit 4056d87335
27 changed files with 285 additions and 404 deletions

View File

@@ -1,4 +1,4 @@
import { Operator } from "../functions";
import { Operator, OperatorSchema } from "../functions";
import i18next from "i18next";
const compileTimeOperatorList: {basename: string}[] = import.meta.compileTime("../compiletime/operatorDescription.ts"); // The will compile to ["impose", "extractPages", etc...]
@@ -7,7 +7,6 @@ export async function getOperatorByName(name: string): Promise<typeof Operator |
// Check if exists
if(!compileTimeOperatorList.find(e => e.basename == name)) return;
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; console.log(t) });
const loadedModule = await import("../functions/" + name + ".ts");
const operator = loadedModule[capitalizeFirstLetter(name)];
if(!operator) {
@@ -16,6 +15,19 @@ export async function getOperatorByName(name: string): Promise<typeof Operator |
return operator;
}
export async function getSchemaByName(name: string): Promise<OperatorSchema | undefined> {
// Check if exists
if(!compileTimeOperatorList.find(e => e.basename == name)) return;
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; console.log(t) });
const loadedModule = await import("../functions/" + name + ".schema.ts");
const schema = loadedModule.default;
if(!schema) {
throw Error("This operator does not export its class in the correct format.")
}
return schema;
}
export function listOperatorNames(): string[] {
const availableOperators = compileTimeOperatorList.map(e => e.basename);
return availableOperators;