Öffentliche API zur MathCoach-IDE
tmp
jsteuer
2019-12-11 73b20b5cc3f198a027c7ee9480d6051f2c095c99
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;
}