From 73b20b5cc3f198a027c7ee9480d6051f2c095c99 Mon Sep 17 00:00:00 2001 From: jsteuer <jan.steuer.htw@gmail.com> Date: Wed, 11 Dec 2019 07:56:57 +0100 Subject: [PATCH] tmp --- src/index.ts | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3d8644f..152abf3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,3 +64,32 @@ } } + + +/** + * Kontext-Datei auf Aufgaben-Datei abbilden. + * Beispiel: "/path/to/myExercise.mcq.json" zu "/path/to/myExercise.groovy" + */ +export function contextFileToExerciseFile(contextFile: MathCoach.File): MathCoach.File { + if (contextFile) { + if (!contextFile.owner || !(typeof contextFile.owner === "string") || !(contextFile.owner.trim() === "")) { + throw new Error("Context file has no valid 'owner' property."); + } + if (!contextFile.part || !(typeof contextFile.part === "string")) { + if (contextFile.part !== "vfs" && contextFile.part !== "www") { + throw new Error("Context file has no valid 'part' property. Allowed values are 'vfs' and 'www'."); + } + } + if (!contextFile.path || !(typeof contextFile.path === "string") || !(contextFile.owner.trim().startsWith("/"))) { + throw new Error("Context file has no valid 'path' property."); + } + } else { + throw new Error("No context file object given.") + } + let file: MathCoach.File = { + part: contextFile.part, + owner: contextFile.owner, + path: contextFile.path.split(".")[0] + ".groovy" + }; + return file; +} -- Gitblit v1.10.0-SNAPSHOT