# Program zum Erstellen ein neu JS-Program import sys import os.path html_template = \ """ {program}

(Something about your program here)

Instruction to user

	
""" js_template = \ """/* * {program}.js * */ import "./lib/dfhi.js"; import * as JXG from "jsxgraph" ; import {{exportBoard}} from "./lib/dfhi-plot"; let board = undefined; function initBoard () {{ return JXG.JSXGraph.initBoard('plotter', {{ boundingbox: [-2, 9, 3, -1], axis: true }}); }} window.init = function() {{ terminal.printl(`Program {program} initializes ... `); board = initBoard(); document.getElementById("export") .addEventListener("click", (event) => exportBoard(board)); }}; window.main = function(...argv) {{ terminal.printl(`program runs with arguments ${{argv}}`); if (board) {{ JXG.JSXGraph.freeBoard(board); board = undefined; }} board = initBoard(); }}; """ def write_program(file_name, template, program_name): code = template.format(program=program_name) print("Write " + code + " to file " + file_name) if os.path.exists(file_name): raise ValueError("File " + file_name + " exist") else: with open(file_name,"w") as f: f.write(code) if __name__ == "__main__": programm_name = sys.argv[1] write_program("src/" + programm_name + ".html", html_template, programm_name) write_program("src/" + programm_name + ".js", js_template, programm_name)