| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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; |
| | | } |